简体   繁体   中英

Linker Error when building Xcode project using external library

I am attempting to build a very simple command line application, in Xcode, that will print out basic information about MXF video files. In order to do this I need to use the libmxf, libbmx, and libbmx libraries available for download here:

http://sourceforge.net/p/bmxlib/home/Home/

My C++ code is incredibly simple at this point:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cerrno>
#include <vector>

#include <bmx/mxf_reader/MXFFileReader.h>
#include <bmx/mxf_reader/MXFGroupReader.h>
#include <bmx/mxf_reader/MXFSequenceReader.h>
#include <bmx/mxf_reader/MXFFrameMetadata.h>
#include <bmx/MXFUtils.h>
#include <bmx/Utils.h>

using namespace std;
using namespace bmx;

#define MXF_OPEN_READ(fn, pf)   mxf_disk_file_open_read(fn, pf)

int main(int argc, const char * argv[])
{
    std::vector<const char *> filenames;
    std::cout << "mxfheader: execution beginning...\n";
    for (int cmdln_index = 0; cmdln_index < argc; cmdln_index++) {
        if (!check_file_exists(argv[cmdln_index])) {
            if (argv[cmdln_index][0] == '-') {
                fprintf(stderr, "Unknown argument '%s'\n", argv[cmdln_index]);
            } else {
                fprintf(stderr, "Failed to open input filename '%s'\n", argv[cmdln_index]);
            }
            return 1;
        }
        filenames.push_back(argv[cmdln_index]);
    }

    std::cout << filenames[0] << "\n";
    return 0;
}

When I compiled the BMX library, I was sure to run configure with 64-bit support, like so:

./configure --build=x86_64-apple-darwin11.4.2 --host=x86_64-apple-darwin11.4.2 CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" LDFLAGS="-arch x86_64" CC=clang CXX=clang++

In the XCode Project under Build Settings, I have added /usr/local/lib to my Search Paths. Under Build Phases, I have added "libbmx-0.1.3.dylib", "libMXF-1.0.4.dylib", and "libMXF++-1.0.4.dylib" to the "Link Binary With Libraries" section.

I have verified that these libraries are, indeed, 64-bit ( file libbmx-0.1.3.dylib returns libbmx-0.1.3.dylib: Mach-O 64-bit dynamically linked shared library x86_64 ).

Every time I try and build the application, I get the following linker error:

Ld /Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug/mxfheader normal x86_64
    cd /Users/ned/Documents/src/mxfheader
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug -L/usr/local/lib -F/Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug -filelist /Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Intermediates/mxfheader.build/Debug/mxfheader.build/Objects-normal/x86_64/mxfheader.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -lbmx-0.1.3 -lMXF-1.0.4 -lMXF++-1.0.4 -o /Users/ned/Library/Developer/Xcode/DerivedData/mxfheader-bkwawmplsoqpdadfxartceqkbolo/Build/Products/Debug/mxfheader

Undefined symbols for architecture x86_64:
  "bmx::check_file_exists(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help would be appreciated. Thanks!

Your problem is the option: -stdlib=libc++ in the command line. It's causing a link to the wrong libc++, you need to make it -stdlib=libstdc++ , as this is the stdlib that the libbmx library is compiled against.

under the Apple LLVM compiler options for the C++ standard library, select: libstdc++ , or pick compiler default (which should choose libstdc++ also)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM