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.
I'm trying to use the fmt (https://github.com/fmtlib/fmt) formatting header library in my c++ project.
I've added the path to the core header file at the top of my main file like so:
#include "../third_party/fmt/core.h"
but when I try to call any function like:
string message = fmt::format("The answer is {}", 42);
I get the following error:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > fmt::v5::internal::vformat<char>(fmt::v5::basic_string_view<char>, fmt::v5::basic_format_args<fmt::v5::buffer_context<char>::type>)", referenced from:
std::__1::basic_string<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type, std::__1::char_traits<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type>, std::__1::allocator<std::__1::enable_if<internal::is_string<char [17]>::value, fmt::v5::internal::char_t<char [17]>::type>::type> > fmt::v5::format<char [17], int>(char const (&) [17], int const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
I'm not sure how to use this as this is how I have used other header libraries in the past such as cxxopts. Any help would be appreciated!
You should link with the fmt library or use the optional header-only mode.
For example, if you have the file test.cc:
#include <fmt/core.h>
int main() {
fmt::print("The answer is {}.", 42);
}
You can compile and link it with gcc:
g++ -std=c++11 test.cc -lfmt
From a comment in #vitaut's answer, if you change your #include line from this:
#include "../third_party/fmt/core.h"
to this:
#include "../third_party/fmt/format.h"
it will cause the code to be compiled in "header-only mode", and you won't need to change your build process to compile and link in the {fmt} library.
I'm working on Mac, and I did not realize that you can install the library using brew. It appears at the end of the page. I have been dealing with symbol errors all evening, and I'm not sure that all my problems were related to the build process. The compiling process was also not working properly.
The paths where the library is installed are: /usr/local/include and /usr/local/lib.
I'm using g++-11 to build my project and this instruction works for me:
g++-11 -std=c++20 -I/usr/local/include -L/usr/local/lib -lfmt main.cpp -o main
The only problem is that it works partially. It works fine with print:
fmt::print("Don't {}!\n", "panic");
But it breaks using format:
fmt::format("Don't {}!\n", "panic");
I'm missing something, but I'm not sure what.
By the way, if you are using VSCode, you can create a c_cpp_properties.json into your .vscode folder and add the include path for the headers.
{
"includePath": [
[...],
"/usr/local/include/"
],
}
Not sure if this is related to your case, but I hope it helps.
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?
First of all I want to say I realise this has been asked a dozen times, and I've read countless solutions without any luck so therefore I'm asking again.
I'm using OS X Mavericks 10.9.5, writing in Sublime 3 and compiling using terminal with g++
I'm trying to compile this simple file (test.cpp)
#include <iostream>
#include <SDL2/SDL.h>
int main () {
if(SDL_Init(SDL_INIT_VIDEO)) {
std::cout << "I made it this far" << std::endl;
}
return 0;
}
Compiler line :
g++ test.cpp
This returns the error :
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
_main in test-ebbae4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So, I've tried adding a lot of different flags, -m32 only changes the result to throw Undefined symbols for architecture i386: and ld: symbol(s) not found for architecture i386
I've tried different -arch variations, but I can't seem to get it to work. also played around with -l -I flags but I'm not sure I know what they do/how they could help..
Does anyone have a clue what to do next?
EDIT : Some additional information. I've tried using the .framework for SDL2, that didn't change anything, currently I'm using SDL2 installed through compilation of the source. Headers located in usr/local/SDL2
g++ test.cpp
You should specify the SDL library, too:
g++ test.cpp -lsdl2
You might need to include a path if its not well known to the compiler driver:
g++ test.cpp -L/path/to/the/library -lsdl2
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.