I've been trying for hours to get Boost C++ libraries working on MacOS 10.13.6.
I'm up-to-date with Xcode and Homebrew.
I used brew install boost to install boost and followed the Boost Getting Started instructions for help with compiling.
I've tried everything that I can think of and read every post I can find on StackOverflow about this.
I'm attempting to compile with:
g++ -std=c++17 -stdlib=libc++ -I /usr/local/opt/boost/include -L /usr/local/opt/boost/lib ass3.cpp -o ass3 -lboost_filesystem
and I get the following error message:
Undefined symbols for architecture x86_64: "boost::system::detail::generic_category_ncx()", referenced from: boost::system::generic_category()
in ass3-3dc386.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I haven't yet tried to install Boost from source.
If I exclude -std=c++17 the code will compile with a warning that I am using c++11 alias. As I get further into my project I'll be using c++17 specific features so I need to include this as far I as I know.
Compiler warning:
warning: alias declarations are a C++11 extension [-Wc++11-extensions]
What am I missing?
Related
UPDATE
I've sorted this by explicitly adding the appropriate -I and -L options, but I'm curious as to why this is necessary now when it wasn't before? On the plus side those annoying library out-of-sync warnings are gone.
UPDATE ENDS
I've broken my OSX OpenGL build environment. I'm building from terminal (using make) with g++, for example:
g++ -o myprog main.o -lglfw -lglew -framework OpenGL
and getting errors:
ld: library not found for -lglfw clang: error: linker command failed with exit code 1 (use -v to see invocation)
These are in addition to compiler errors such as:
g++ -c main.cpp main.cpp:3:10: fatal error: 'GL/glew.h' file not found
So it seems the OpenGL libraries and includes have been lost. Everything was working fine until I executed the command:
export SDKROOT="$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
Which I did to try and fix warning messages like:
ld: warning: text-based stub file /System/Library/Frameworks//OpenGL.framework/OpenGL.tbd and library file /System/Library/Frameworks//OpenGL.framework/OpenGL are out of sync. Falling back to library file for linking.
I got that 'fix' from here: macOS framework lib problem
I realise it was reckless running commands that I don't fully understand but nonetheless... now I can't compile/link any OpenGL code and after scouring the internet for help I've come up with nothing, so here I am.
I'm running OSX 10.13.6 on a 2013 MacBook Pro.
First post BTW so please forgive me if I've not provided enough detail.
Basic Info:
system: macOS High Sierra(10.13.6)
editor : vs code(latest version)
Compiler: g++ (Xcode)
Target:deploy GLFW + GLAD
Question Description:
Recently, I'm learning to do some Computer Graphics related work. Everything is going smooth. However, when i create a window to test the env.Link error happened:
Undefined symbols for architecture x86_64:
"_gladLoadGLLoader", referenced from:
_main in main-5c211c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1
It seems I have not link some third party file. I
have fixed exactly the same problem by add "-lglfw" args to g++ when using functions in glfw3.h.
But when meeting glad related function : gladLoadGLLoader, I don't know how to do.
Something I have done:
Can find the head file.
#include glad/glad.h
#include GLFW/glfw3.h
Have put the file "glad.c" in workspace.
Try to Add "g++ -framework XXXXX" , But doesn't work.
Try to Add "g++ -lglfw3", But doesn't work.
Add "g++ -L or I /usr/lib or /usr/local/lib or /usr/local/include", But doesn't work.
Just tell the g++ to compile glad.c by adding "glad.c" to args. I thought glad.c will be compiled by default. Although I am not clear what happened, the problem is resolved anyway.
Add glad.c into Build Phases->Compile Sources
First, I create a c++ console project.
Then, I download the lua5.2.0 from lua.org, then make the lib use [make macosx test] and got the liblua.a.
Finally, I import the lua src into project and drag the liblua.a in project, write some demo code and compile,but get the link error, I confirm there has no grammar error.
Ld /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug/LuaAdapter normal x86_64
cd /Users/luocaixin/Desktop/xcodeWS1/LuaAdapter
export MACOSX_DEPLOYMENT_TARGET=10.10
/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.10.sdk -L/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug -L/Users/luocaixin/Desktop/xcodeWS1/LuaAdapter/Lua.5.2.0/src -F/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug -filelist /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/LuaAdapter.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -llua -Xlinker -dependency_info -Xlinker /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/LuaAdapter_dependency_info.dat -o /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug/LuaAdapter
duplicate symbol _main in:
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/lua.o
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/luac.o
duplicate symbol _main in:
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/lua.o
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/main.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I want to know what cause this error and how to import lua in xcode c++
project correctly.
Did you read the error? It's telling you what's wrong: you have more than one main function. You've included two object files that contain a main function (lua, luac) and probably have one in your test app, too. You need to leave those files out of your project. They are the reference command line interpreter and compiler, respectively. You don't include them if you're embedding Lua as a library.
I'm trying to learn FLTK for C++ and I'm working on a Macbook with the clang++ compiler. Whenever I try to link the library like this:
clang++ -L/usr/local/lib -lfltk
It gives me this error:
clang: warning: argument unused during compilation: '-X11'
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've looked on a couple other forums to see how to fix this problem and haven't gotten any answers that worked. I also tried reinstalling Command Line Tools from Apple's Developer site.
You have to make sure you put the linker command (-L/usr/local/lib -lfltk) before doing filename.cpp -o Exectuable but still in the same line in the command line.
I'm using OSX Mountain Lion. I just downloaded, unpacked, and built boost 1.52.0 using the instructions supplied from the boost website: http://www.boost.org/doc/libs/1_52_0/more/getting_started/unix-variants.html. I left the default installation prefix at /usr/local, meaning that the libraries are installed in /usr/local/lib and the header files are in /usr/local/include. I have verified that the libraries and headers are present there and recently modified.
I'm attempting to compile the boost asynchronous I/O example found here: http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/tutorial/tuttimer5/src.html (source).
Here is my compilation command:
g++ -Wall -c -g -I/usr/local/include src/test1.cpp -o src/test1.o
where src/test1.cpp is the example source file. Here is my linking command (and error):
g++ -Wall -L/usr/local/lib -lboost_thread -lboost_system src/test1.o -o bin/test1
Undefined symbols for architecture x86_64:
"boost::thread::~thread()", referenced from:
_main in test1.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I have tried using both Apple's clang++ 4.0 and g++ 4.6.0. I get the same undefined symbol error from both programs.
Other people seem to have had trouble compiling this code sample as well. I am aware of this question: C++ / Boost: Undefined Symbols in example? and this one: Linker error when compiling boost.asio example. However, each of these problems seems to have been fixed by adding the appropriate switches (-lboost_thread and -lboost_system) to the command line. I already have those. I have also tried adding -lpthread without luck.
Thank you for taking time to look at my question! Any help is appreciated. :)
Just ran into this same problem, and I found that reverting to Boost 1.49 fixes the problem. Download links for Boost 1.49 are here:
http://www.boost.org/users/history/version_1_49_0.html
Before installing 1.49, I removed 1.52 by deleting /usr/local/include/boost and /usr/local/lib/*boost*. Not sure what changed between 1.49 and 1.52 to cause this problem, or whether Boost 1.50 or 1.51 will work.
Put the libraries you link with last on the command line.
The GNU linker uses kind of reverse lookup of dependencies, so if file A depends on library B, B should come after A on the command line.