I am trying to compile dynamic lib in Mac OS X Mavericks, but when I try to link it, it says:
Undefined symbols for architecture i386:
"operator new(unsigned long, int, char const*, int)", referenced from:
...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Compile flags I use:
Wall -Wextra -m32 -march=pentium4 -arch i386 -fvisibility=hidden
tried with
-stdlib=libc++ -lstdc++ -lc++
not helping.
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Please help!
EDIT:
Ok, lack of attention:
ld: symbol(s) not found for architecture i386
So, figured out that this is only happening when -g flag is present :)
For release build there is no error.
The question that arises is why there is no debug information symbols on MacOS X for libc++ (operator new). Any clues?
Related
There are lots of threads that have similar questions, but many deal with c++ code and have c++ solutions. However, from what I gather on the various threads, I might be missing a library when gcc is trying to link libraries.
I don't know which library I need to include though, for JSON1 to build successfully.
For loading SQLite extensions, their official instructions on the Mac is:
gcc -g -fPIC -dynamiclib YourCode.c -o YourCode.dylib
So I have done:
$ gcc -g -fPIC -dynamiclib sqlite-src-3180000/ext/misc/json1.c -o json1
sqlite-src-3180000/ext/misc/json1.c:344:11: warning: implicit declaration of function
'sqlite3_value_subtype' is invalid in C99 [-Wimplicit-function-declaration]
if( sqlite3_value_subtype(pValue)==JSON_SUBTYPE ){
^
sqlite-src-3180000/ext/misc/json1.c:501:3: warning: implicit declaration of function
'sqlite3_result_subtype' is invalid in C99 [-Wimplicit-function-declaration]
sqlite3_result_subtype(pCtx, JSON_SUBTYPE);
^
2 warnings generated.
Undefined symbols for architecture x86_64:
"_sqlite3_result_subtype", referenced from:
_jsonArrayFunc in json1-5de683.o
_jsonExtractFunc in json1-5de683.o
_jsonObjectFunc in json1-5de683.o
_jsonQuoteFunc in json1-5de683.o
_jsonArrayFinal in json1-5de683.o
_jsonObjectFinal in json1-5de683.o
_jsonReturnJson in json1-5de683.o
...
"_sqlite3_value_subtype", referenced from:
_jsonAppendValue in json1-5de683.o
"_sqlite3_vsnprintf", referenced from:
_jsonPrintf in json1-5de683.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What am I missing?
This is my gcc details, if it helps:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I am trying to use --thread-sanitizer option of clang on OSX:
$ clang++ -fthread-sanitizer -fpic tsan1.cc
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
[...]
clang -cc1 version 4.2 based upon LLVM 3.2svn default target x86_64-apple-darwin12.3.0
[...]
Undefined symbols for architecture x86_64:
"___tsan_func_entry", referenced from:
threadfunc(void*) in tsan1-6f7gbr.o
[...]
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Looks like a linkage error. Should I link with some additional libs?
ThreadSanitizer is unsupported on Darwin for C++ yet. This is unlikely to change in at least half a year.
It's been fixed.
According to https://clang.llvm.org/docs/ThreadSanitizer.html
ThreadSanitizer is supported on the following OS:
... Darwin arm64, x86_64, ...
Also I just used it without any problems.
I know there are several questions regarding this. I have looked through them all but still haven't found an answer.
I'm trying to use SDL with xCode on my Mac. I'm using xCode 4.5
I followed this tutorial exactly, twice! I even tried a second tutorial which was basically the same and it still didnt compile.
When i compile i get this error:
Ld /Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug/SDL_SetUp normal x86_64
cd "/Users/shardy/Desktop/shardy/C++ Programs/GlutApps/SDL_SetUp"
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/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug -F/Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug -F/Library/Frameworks -filelist /Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Intermediates/SDL_SetUp.build/Debug/SDL_SetUp.build/Objects-normal/x86_64/SDL_SetUp.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -framework SDL -framework Cocoa -o /Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug/SDL_SetUp
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Followed by:
"_main", referenced from:
Start in crt1.10.6.o
(maybe you meant:_SDL_main)
Symbol(s) not found for architecture x86_64
Linker command failed with exit code 1 (use -v to see invocation)
I was originally using xCode 4.3 and it wouldnt compile, so i updated to xCode to 4.5 thinking maybe xCode was causing issues and tried everything again, but unfortunately, still did not compile...
I am not experienced enough to know how to fix this and i am out of relatable threads to read...
Thanks.
I have succesfully compiled the LLVM kalidoscope examples in C.
Now I'm extending the code with:
#include "llvm/Support/CommandLine.h"
static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"), cl::Required);
int mail(...
now i compile using:
clang++ -g toy.cpp llvm-config --cppflags --ldflags --libs all -O3 -o toy
and after this change i receive the following error:
Undefined symbols for architecture x86_64:
"typeinfo for llvm::cl::GenericOptionValue", referenced from:
typeinfo for llvm::cl::OptionValueCopy<std::string> in toy-Pq1GSI.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What could be wrong, and how can i fix it?
Versions:
clang++ -v Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix
brew info llvm llvm: stable 3.2 (bottled), HEAD http://llvm.org/ /usr/local/Cellar/llvm/3.2 (628 files, 106M) * https://github.com/mxcl/homebrew/commits/master/Library/Formula/llvm.rb
==> Options
--all-targets Build all target backends
--universal Build a universal binary
--rtti Build with C++ RTTI
--shared Build LLVM as a shared library
--with-clang Build Clang C/ObjC/C++ frontend
==> Caveats Extra tools and bindings are installed in /usr/local/Cellar/llvm/3.2/share/llvm and /usr/local/Cellar/llvm/3.2/share/clang.
It seems that changing the compile command to this is a fix:
clang++ -g toy.cpp llvm-config --cxxflags --ldflags --libs -O3 -o toy
I'm working with FFMPEG on Mac OSX, my Mac version is 10.6.8 (i386).
When I try to compile my C++ code linking a dynamic library:
g++ sdk.cpp -rpath /usr/local/lib/libinsight.dylib -o sdk
I get the following error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
"av_open_input_file(AVFormatContext**, char const*, AVInputFormat*, int, AVFormatParameters*)", referenced from:
ffmpeg_open(AVFormatContext**, char const*, int*)in ccCkx9dd.o
(so forth fo every FFMPEG call)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Without linking dylib I have no problem. What's the matter?
P.S. ffmpeg version is Mach-O 64-bit executable x86_64
g++ sdk.cpp -rpath /usr/local/lib/libinsight.dylib -o sdk
Shouldn't you be linking to libffmpeg somewhere? Try adding -lffmpeg to your link command line.