This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 5 months ago.
I am trying to implement my own thumbnail provider by following Microsoft's thumbnail provider code sample. The code has been coming together nicely, but now I needed to figure out a way to compile (on Windows). MSYS2 appears to be a popular option.
g++ -shared -o GrmgThumbnailProvider.dll -lshlwapi -lgdi32 Dll.cpp GrmgThumbnailProvider.cpp
This causes errors:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Zyl\AppData\Local\Temp\cc5HnXOH.o:Dll.cpp:(.text$_ZN13CClassFactory14QueryInterfaceERK5_GUIDPPv[_ZN13CClassFactory14QueryInterfaceERK5_GUIDPPv]+0x31): undefined reference to `QISearch'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Zyl\AppData\Local\Temp\ccXzQLhd.o:GrmgThumbnailProvider.cpp:(.text+0x36f): undefined reference to `__imp_CreateDIBSection'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Zyl\AppData\Local\Temp\ccXzQLhd.o:GrmgThumbnailProvider.cpp:(.text$_ZN18CGrmgThumbProvider14QueryInterfaceERK5_GUIDPPv[_ZN18CGrmgThumbProvider14QueryInterfaceERK5_GUIDPPv]+0x31): undefined reference to `QISearch'
collect2.exe: error: ld returned 1 exit status
The libraries are definitely found: g++ complains if I change the library names in the -l argument to some nonsense. How is it these references cannot be resolved despite the required libraries being both present and found?
QISearch
CreateDIBSection
Related
This question already has answers here:
How to use the fmt library without getting "Undefined symbols for architecture x86_64"
(3 answers)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed last year.
I'd like to make a python-like dynamic integer class in C++ as an experiment. It requires me to change many integers to string types. As in here: https://www.zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html it states that fmt format_int will be best for that kind of job.
So I installed fmt with command sudo apt-get install libfmt-dev
I added a header #include <fmt/format.h>
Used it in a simple test main
int main()
{
std::cout<<fmt::format_int(124236695253045068).str();
}
And tried to compile with g++ -lfmt -std=c++17 dynamic\ mem.cc
Output of the compiler is as follows:
/usr/bin/ld: /tmp/ccLBcSNm.o: in function `fmt::v6::format_int::format_decimal(unsigned long long)':
dynamic mem.cc:(.text._ZN3fmt2v610format_int14format_decimalEy[_ZN3fmt2v610format_int14format_decimalEy]+0x94): undefined reference to `fmt::v6::internal::basic_data<void>::digits'
/usr/bin/ld: dynamic mem.cc:(.text._ZN3fmt2v610format_int14format_decimalEy[_ZN3fmt2v610format_int14format_decimalEy]+0xad): undefined reference to `fmt::v6::internal::basic_data<void>::digits'
/usr/bin/ld: dynamic mem.cc:(.text._ZN3fmt2v610format_int14format_decimalEy[_ZN3fmt2v610format_int14format_decimalEy]+0xfa): undefined reference to `fmt::v6::internal::basic_data<void>::digits'
/usr/bin/ld: dynamic mem.cc:(.text._ZN3fmt2v610format_int14format_decimalEy[_ZN3fmt2v610format_int14format_decimalEy]+0x113): undefined reference to `fmt::v6::internal::basic_data<void>::digits'
/usr/bin/ld: /tmp/ccLBcSNm.o: in function `std::make_unsigned<long>::type fmt::v6::internal::to_unsigned<long>(long)':
dynamic mem.cc:(.text._ZN3fmt2v68internal11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v68internal11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_]+0x2b): undefined reference to `fmt::v6::internal::assert_fail(char const*, int, char const*)'
collect2: error: ld returned 1 exit status
Do you have any ideas what went wrong? I don't usually link non-standard libraries so I don't have any idea what to do about it.
Use
$ g++ -std=c++17 dynamic\ mem.cc -lfmt
fmt is provided as a static library (.a). With those, the order is important as the linker takes out of a library only the objects which are needed to provide symbols to other objects or libraries which precede them in the command line. If you start with a library, there is only main which is missing and usually libraries don't provide main, so they are ignored. When putting the library after your source code, the symbols missing in your code are searched in the library.
(In case of circular dependencies, you may even have to provide a library several times)
This question already has answers here:
undefined reference to main for shared library
(1 answer)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 2 years ago.
I am justing wondering what the error means here if anyone can help me.
g++ -o Try2 student.o studentlist.o
Undefined first referenced
symbol in file
main /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.4/crt1.o
ld: fatal: Symbol referencing errors. No output written to Try2
collect2: error: ld returned 1 exit status
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I am trying to use the library gnuplot-iostream in Netbeans with Windows/Cygwin, but merely including it in my source leads to compilation problems. I have already downloaded boost with the Cygwin interface. Yet, the message I get is:
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++ -o dist/Debug/Cygwin_4.x-Windows/welcome_1 build/Debug/Cygwin_4.x-Windows/welcome.o -L../../../../../cygwin64 -L../../../../../cygwin64/lib/curl -L../../../../../cygwin64/bin -lcygcurl-4
build/Debug/Cygwin_4.x-Windows/welcome.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:222:(.text+0x51ca): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:223:(.text+0x51d6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
/usr/include/boost/system/error_code.hpp:224:(.text+0x51e2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin_4.x-Windows/welcome_1.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/welcome_1.exe] Error 1
I haven't made any reference to the library besides including it:
#include "gnuplot-iostream.h"
I also can't find any mention of this error. Does anybody know what I am doing wrong?
Thanks
I believe you are saying the problem is with not properly linking to the boost libraries, correct?
You see that -lcygcurl-4? This actually links your code with the curl implementation. The library search -L<xxx> pathes you have for boost look fine, but you'll have still need to specify particular libraries found there and need being linked to your program.
If you specify linking additional libraries using the -l<yyy> option, these are resolved as looking up lib<yyy>.a (or lib<yyy>.lib) in your actual build environment.
As mentioned just applying an #include <yyy.hpp> isn't enough to tell the toolchain (linker) where the actual implementation comes from. Add the library the same way you've added that cygcurl-4 libraray with your IDE/build system.
Transferred discussion from comments, to make this an answer (poor I know and I've marked the duplicates already. It's just because this simple clarification doesn't fit a comment very well apparently)
Just to keep this registered if someone else needs it. To solve the problem it was needed to add a -lboost_system-mt in the linker. To do so in Netbeans one has to right-click on the project, choose Properties, then go to Linker (which is under Build). There will be an option for Compilation Line. The flag should be added there.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I just want to start in openGL programming, so I installed freeglut3 from the repositories of ubuntu and I have all mesa packages installed, as well as build-essentials.
Later, I copied one simple example of openGL wiki
In first, I tried to compile it with: gcc triangle.c -o triangle.o;
but, later, I read here: Linker error : undefined reference to symbol 'glOrtho' that i have to linked the libraries with -l.
So, I tried with gcc triangle.c -lglut -lGL -Wall -o triangle.o
Both return the same error:
/tmp/ccKLT4ac.o: In function `main':
triangle.c:(.text+0x2b): undefined reference to `glutInit'
triangle.c:(.text+0x37): undefined reference to `glutInitDisplayMode'
triangle.c:(.text+0x4b): undefined reference to `glutInitWindowSize'
triangle.c:(.text+0x57): undefined reference to `glutCreateWindow'
triangle.c:(.text+0x5c): undefined reference to `glewInit'
triangle.c:(.text+0x73): undefined reference to `glewGetErrorString'
triangle.c:(.text+0xaa): undefined reference to `glutDisplayFunc'
triangle.c:(.text+0xaf): undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status
I've tried to include gl.h & glu.h libraries, try with a lot of different example programs in cpp,... and a lot of combinations. All return similar errors.
ah, in /usr/include I have all the libraries:
akronix#ASJ-Netbook:~$ ls /usr/include/GL
freeglut_ext.h glext.h glu_mangle.h glx.h glxproto.h
freeglut.h gl.h glut.h glxint.h glxtokens.h
freeglut_std.h gl_mangle.h glxew.h glx_mangle.h internal
glew.h glu.h glxext.h glxmd.h wglew.h
Try to compile by placing libraries at the last
gcc triangle.c -Wall -o triangle -lglut -lGL
This question already has an answer here:
g++ and boost linker error on Ubuntu oneiric
(1 answer)
Closed 8 years ago.
folks!
I'm using ubuntu 12.04 and trying to compile a boost test program. I installed boost with
sudo apt-get install libboost-all-dev
an so, I don't know where i can find my libraries. I tried do compile that using
g++ -lboost_system -lboost_thread boost_test.cpp
thinking maybe to have some default path where ubuntu installed boost automatically, but it was wrong and I had the following:
/tmp/ccTKXzTR.o: In function
__static_initialization_and_destruction_0(int, int)':
boost_test.cpp:(.text+0xcc): undefined reference to
boost::system::generic_category()' boost_test.cpp:(.text+0xd8):
undefined reference to boost::system::generic_category()'
boost_test.cpp:(.text+0xe4): undefined reference to
boost::system::system_category()' /tmp/ccTKXzTR.o: In function
boost::system::error_code::error_code()':
boost_test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17):
undefined reference toboost::system::system_category()'
/tmp/ccTKXzTR.o: In function
boost::asio::error::get_system_category()':
boost_test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5):
undefined reference toboost::system::system_category()'
/tmp/ccTKXzTR.o: In function
boost::asio::detail::posix_tss_ptr_create(unsigned int&)':
boost_test.cpp:(.text._ZN5boost4asio6detail20posix_tss_ptr_createERj[_ZN5boost4asio6detail20posix_tss_ptr_createERj]+0x19):
undefined reference topthread_key_create' /tmp/ccTKXzTR.o: In
function
boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service,
boost::asio::detail::task_io_service::thread_info>::context>::~posix_tss_ptr()':
boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED5Ev]+0x15): undefined reference topthread_key_delete' /tmp/ccTKXzTR.o: In
function
boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl,
unsigned char>::context>::~posix_tss_ptr()':
boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED5Ev]+0x15):
undefined reference topthread_key_delete' collect2: error: ld
returned 1 exit status
Can someone help-me to figure out if my library is correctly installed and compile that?
I found out /usr/include/boost is the path to boost headers and /usr/lib contains all boost libraries i want to.