Linker error while creating an Xcode project using an external library

I am trying to create a very simple command line application in Xcode that will print basic information about MXF video files. 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 that I was running configure with support for the 64-bit version, for example:

 ./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, in the Build Settings section, I added / usr / local / lib to my search paths. In the "Phase Build" section, I added "libbmx-0.1.3.dylib", "libMXF-1.0.4.dylib" and "libMXF ++ - 1.0.4.dylib" to the "Linking to Libraries" section.

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

Every time I try to create an 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 greatly appreciated. Thanks!

+4
source share
1 answer

Your problem is this: -stdlib=libc++ on the command line. This leads to a link to the wrong libC ++, you need to make it -stdlib=libstdc++ , since this is the stdlib with which the libbmx library is libbmx .

in the Apple LLVM compiler settings for the C ++ standard library, select: libstdc++ or select compiler default (which libstdC ++ should also select)

+9
source

Source: https://habr.com/ru/post/1440005/


All Articles