matehat / Objective-LevelDB

An Objective-C database library built over Google's LevelDB

Home Page:http://matehat.github.io/Objective-LevelDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linker command failed - duplicate symbol _main for architecture x86_64

lanceschi opened this issue · comments

I'm getting this linking issue even with a default empty project.

Deployment target 8.3
Using Objective-LevelDB (2.1.4) installed via Cocoapods
Using leveldb-library (1.18.1) installed via Cocoapods

Here's the Podfile:

platform :ios, '8.0'
use_frameworks!

target 'levelDB_test' do
  pod 'Objective-LevelDB'
end

target 'levelDB_testTests' do
  pod 'Objective-LevelDB'
end

Here's the error log:

duplicate symbol _main in:
    /Users/luca/Library/Developer/Xcode/DerivedData/levelDB_test-gqscfpqoazdhylfthcxwbyirjqjw/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-levelDB_test-leveldb-library.build/Objects-normal/x86_64/db_bench.o
    /Users/luca/Library/Developer/Xcode/DerivedData/levelDB_test-gqscfpqoazdhylfthcxwbyirjqjw/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-levelDB_test-leveldb-library.build/Objects-normal/x86_64/leveldb_main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any suggestions will be appreciated.

Thanks.

Cheers,
Luca

Removing use_frameworks! line from the Podfile fixed the compiling issue.

Hi,

I'm getting this issue when I try to set Objective-LevelDB as a dependency in a podspec file. Do you know any solution for this? Thanks!

@ov1d1u can you post your Podfile?

As I said before I'm not using a Podfile but a podspec file, where I set Objective-LevelDB as a depedency. Here is the podspec file: http://pastebin.com/STzBHNm6 (the last 5 lines are relevant, I guess).

I get the issue when I run pod spec lint to validate the podspec file

@ov1d1u weird! I checked your file. My only guess to better identify your issue is to comment s.requires_arc = true and try rebuilding.

I already did this with no effect. I'll see what can I do regarding this. Anyway the linker error comes from leveldb-library and not Objective-LevelDB.

@ov1d1u you're right. I realise my mistake a few seconds after I published the comment. I delete the comment right away although it eventually made to your inbox. Sorry.

Is there a solution or workaround to this problem that doesn't involve removing use_frameworks!?

The project I am working on needs to use frameworks and I am running into this issue.

commented

@ov1d1u any solutions for this issue?

commented

this is because duplicated main function in files db_bench.cc and leveldb_main.cc
we can fix that by extending exclude_files by db/db_bench.cc in podspec file, like this:

  "exclude_files": [
    "**/*_test.cc",
    "port/win",
    "db/db_bench.cc"
  ]

@matehat

commented

i've spend some time on this, but finally all is working
i've updated leveldb-library podspec in private spec repo, like this:

{
  "name": "leveldb-library",
  "version": "1.18.1",
  "license": "New BSD",
  "summary": "A fast key-value storage library ",
  "description": "LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.",
  "homepage": "https://github.com/google/leveldb",
  "authors": "The LevelDB Authors",
  "platforms": {
    "ios": "5.0",
    "osx": "10.7"
  },
  "source": {
    "git": "https://github.com/matehat/leveldb.git",
    "tag": "v1.18.1"
  },
  "requires_arc": false,
  "compiler_flags": [
    "-DOS_MACOSX",
    "-DLEVELDB_PLATFORM_POSIX"
  ],
  "preserve_paths": [
    "leveldb-library"
  ],
  "xcconfig": {
    "CC": "clang",
    "CXX": "clang++",
    "HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/leveldb-library\"",
    "OTHER_LDFLAGS": "-lc++"
  },
  "header_dir": "leveldb",
  "source_files": [
    "include/leveldb/*",
    "util/*.{h}",
    "table/*.{h}",
    "port/*.{h}",
    "db/*.{h}",
    "db/builder.cc",
    "db/c.cc",
    "db/db_impl.cc",
    "db/db_iter.cc",
    "db/dbformat.cc",
    "db/filename.cc",
    "db/log_reader.cc",
    "db/log_writer.cc",
    "db/memtable.cc",
    "db/repair.cc",
    "db/table_cache.cc",
    "db/version_edit.cc",
    "db/version_set.cc",
    "db/write_batch.cc",
    "table/block.cc",
    "table/block_builder.cc",
    "table/filter_block.cc",
    "table/format.cc",
    "table/iterator.cc",
    "table/merger.cc",
    "table/table.cc",
    "table/table_builder.cc",
    "table/two_level_iterator.cc",
    "util/arena.cc",
    "util/bloom.cc",
    "util/cache.cc",
    "util/coding.cc",
    "util/comparator.cc",
    "util/crc32c.cc",
    "util/env.cc",
    "util/env_posix.cc",
    "util/filter_policy.cc",
    "util/hash.cc",
    "util/histogram.cc",
    "util/logging.cc",
    "util/options.cc",
    "util/status.cc",
    "port/port_posix.cc"
  ],
  "public_header_files": [
    "include/leveldb/*.{h}",
    "include/**/*.{h}"
  ]
}

Still not work if involve use_frameworks!

commented

did you use my solution, it's still the same error?

@emilwojtaszek May be no, I just insert a line pod 'Objective-LevelDB' into my podfile and run pod install. But it doesn't work. So should I fork this repo and edit my podspec?

commented

not sure but this should work

pod 'leveldb-library', :podspec => 'https://gist.githubusercontent.com/emilwojtaszek/42b63a772ea71bc1fb4a/raw/71ec94bcb417580e84765057a743e1946b016a3c/leveldb-library.json'

@emilwojtaszek the error Linker command failed - duplicate symbol _main for architecture x86_64 is gone, but it comes out: "util/arena.h" not found.

commented

maybe this is to big shortcut..

you should try to create private cocoapods repo as i do and add 2 specs

1:

{
  "name": "Objective-LevelDB-appunite",
  "version": "2.1.4",
  "license": "MIT",
  "summary": "A feature-complete wrapper for LevelDB in Objective-C.",
  "description": "This is a feature-complete wrapper for Google's LevelDB. LevelDB is a fast key-value store written by Google.",
  "homepage": "https://github.com/matehat/Objective-LevelDB",
  "authors": [
    "Michael Hoisie",
    "Mathieu D'Amours"
  ],
  "platforms": {
    "ios": "5.0",
    "osx": "10.7"
  },
  "source": {
    "git": "https://github.com/matehat/Objective-LevelDB.git",
    "tag": "2.1.4",
    "submodules": true
  },
  "source_files": "Classes/*.{h,m,mm}",
  "dependencies": {
    "leveldb-library-appunite": [
      "~> 1.18"
    ]
  },
  "requires_arc": false
}

2.:

{
  "name": "leveldb-library-appunite",
  "version": "1.18.1",
  "license": "New BSD",
  "summary": "A fast key-value storage library ",
  "description": "LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.",
  "homepage": "https://github.com/google/leveldb",
  "authors": "The LevelDB Authors",
  "platforms": {
    "ios": "5.0",
    "osx": "10.7"
  },
  "source": {
    "git": "https://github.com/matehat/leveldb.git",
    "tag": "v1.18.1"
  },
  "requires_arc": false,
  "compiler_flags": [
    "-DOS_MACOSX",
    "-DLEVELDB_PLATFORM_POSIX"
  ],
  "preserve_paths": [
    "leveldb-library"
  ],
  "xcconfig": {
    "CC": "clang",
    "CXX": "clang++",
    "HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/leveldb-library-appunite\"",
    "OTHER_LDFLAGS": "-lc++"
  },
  "header_dir": "leveldb",
  "source_files": [
    "include/leveldb/*",
    "util/*.{h}",
    "table/*.{h}",
    "port/*.{h}",
    "db/*.{h}",
    "db/builder.cc",
    "db/c.cc",
    "db/db_impl.cc",
    "db/db_iter.cc",
    "db/dbformat.cc",
    "db/filename.cc",
    "db/log_reader.cc",
    "db/log_writer.cc",
    "db/memtable.cc",
    "db/repair.cc",
    "db/table_cache.cc",
    "db/version_edit.cc",
    "db/version_set.cc",
    "db/write_batch.cc",
    "table/block.cc",
    "table/block_builder.cc",
    "table/filter_block.cc",
    "table/format.cc",
    "table/iterator.cc",
    "table/merger.cc",
    "table/table.cc",
    "table/table_builder.cc",
    "table/two_level_iterator.cc",
    "util/arena.cc",
    "util/bloom.cc",
    "util/cache.cc",
    "util/coding.cc",
    "util/comparator.cc",
    "util/crc32c.cc",
    "util/env.cc",
    "util/env_posix.cc",
    "util/filter_policy.cc",
    "util/hash.cc",
    "util/histogram.cc",
    "util/logging.cc",
    "util/options.cc",
    "util/status.cc",
    "port/port_posix.cc"
  ],
  "public_header_files": [
    "include/leveldb/*.{h}",
    "include/**/*.{h}"
  ]
}

Thanks ,I'll try it. Now I Just drag the uber's fork repo file to my Swift project. And it runs ok.

@emilwojtaszek thanks infinitely for helping people with this issue. Do you have suggestions as to what could be changed on the project to fix that issue permanently?

commented

you could update podspecs as i've described above, it's working for me

Thanks, will get that going today.

Basically just made a ruby-based spec from your JSON

commented

you should also update CocoaPods Specs

Before pushing the changes to CocoaPods, thus imposing the changes to every new user, I want to make sure we're not breaking things

In my quick tests, I tried starting a new project with different configurations, with the current cocoapods specs (both leveldb-library and Objective-LevelDB) and the projects always builds fine. So it seems the problems you were having were more project-related configurations, and I'd like to find what that is, rather that break the existing setup.

I have been using the Objective-LevelDB pod successfully for a while. Today, I added the XCGLogger pod, which requires the adding use_frameworks! to my pod file because it is written in swift. Now, I'm getting the error duplicate symbol _main for architecture x86_64.

The function int main() is defined in two files: leveldb_main.cc and db_bench.cc. Both files are in leveldb-library and not in Objective-LevelDB itself. Do you know if there is an open issue for this in leveldb-library?

@neirar I just pushed a new version of leveldb-library and of Objective-LevelDB. Can you update your pods and confirm if it fixed your issues?

Seems to have fixed the issue, closing.

@matehat, sorry for the delay in replying. The issue has been fixed. Thanks!