I'm currently trying to build a simple IceCast supplier using libshout.
Unfortunately, I am unable to resolve some linker errors:
Invoking: Cygwin C++ Linker
g++ -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\ogg" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\vorbis" -o "LibshoutJavaAdapter.exe" ./src/LibshoutJavaAdapter.o -lshout -lvorbis -logg -lssl -lcrypto
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/libshout.a(tls.o): In function `tls_setup_process':
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:200: undefined reference to `SSL_is_init_finished'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:200:(.text+0x74): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSL_is_init_finished'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:203: undefined reference to `SSL_is_init_finished'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:203:(.text+0x8f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSL_is_init_finished'
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/libshout.a(tls.o): In function `tls_setup':
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:66: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:66:(.text+0x4ad): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:67: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:67:(.text+0x4b9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:68: undefined reference to `SSLeay_add_all_algorithms'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:68:(.text+0x4be): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSLeay_add_all_algorithms'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:69: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:69:(.text+0x4c7): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
collect2: error: ld returned 1 exit status
I'm using CygWin's GCC 64 bit version, butalso got a 32 version to compile with if needed.
The build is triggered using make
My actual code up to now is pretty basic (I'm only just getting started with this library)
#include <iostream>
#include <shout/shout.h>
int main() {
shout_init();
std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
return 0;
}
I use the following libraries for the linker in this Order(-l):
shout -> the actual library i try to use
vorbis
ogg
ssl
crypto
From the look of the error I suppose, that this is related to ssl somehow, but i did include those didn't I ?
I already tried rotating the order, but that only created more errors, so I suppose the order is correct ...
Edit 1:
As nnovich-OK suggested, I altered my code like this to check OpenSSL:
#include <iostream>
//#include <shout/shout.h>
#include <ctype.h>
#include <openssl/ssl.h>
int main() {
//shout_init();
OPENSSL_init();
OPENSSL_INIT_SETTINGS * test = NULL;
OPENSSL_init_ssl(0,test);
//SSL_is_init_finished();
std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
return 0;
}
There resulting Linking error looks like this:
g++ -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\ogg" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\vorbis" -o "LibshoutJavaAdapter.exe" ./src/LibshoutJavaAdapter.o -lshout -lvorbis -logg -lssl -lcrypto
./src/LibshoutJavaAdapter.o: In function `main':
/cygdrive/d/Install und andere Sachen/Eclipse/C++/LibshoutJavaAdapter/Debug/../src/LibshoutJavaAdapter.cpp:18: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Install und andere Sachen/Eclipse/C++/LibshoutJavaAdapter/Debug/../src/LibshoutJavaAdapter.cpp:18:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
collect2: error: ld returned 1 exit status
I see that there is a problem with OPENSSL_init_ssl from ssl.h but not with OPENSSL_init from crypto.h (witch intern is included by ssl.h)
Does that gives anyone any idea?
Any hints to resolving this Problem appreciated
I don't have the same setup to try, but provided info seems clear enough. Linker can't find functions from ssl library, so you need to focus on linking ssl. I think, issue scenario can be reduced to simple main function calling OPENSSL_init_ssl() (parameters doesn't matter, since you aren't going to execute it) and build process involving linking only openssl. Resolving this linking failure will help to resolve your current case. So let the Google and SO be with you :)
PS I'd rather put all this into comment, but SO newcomers aren't allowed to.
Edit:
Subsequent troubleshooting (check comments below) revealed actual root cause. System has several libssl instances (e.g. some app installation brought another version) and linker used instance not suitable for current build (e.g. 32bit version in building 64bit app). So the solution was to put linker into verbose mode and to check whether library paths are as expected.
Related
a test file named ml.cc, I have already installed the mathgl headers to /usr/local/include and libmgl.a to /usr/local/lib
#include <mgl2/mgl.h>
int main()
{
mglGraph gr;
gr.FPlot("sin(pi*x)");
gr.WriteFrame("test.png");
return 0;
}
"g++ -c ml.cc" can work,but "g++ ml.cc" does not work,the error is
/tmp/ccPzPcZt.o: In function `mglGraph::mglGraph(int, int, int)':
ml.cc:(.text._ZN8mglGraphC2Eiii[_ZN8mglGraphC5Eiii]+0x3b): undefined reference to `mgl_create_graph_gl'
ml.cc:(.text._ZN8mglGraphC2Eiii[_ZN8mglGraphC5Eiii]+0x54): undefined reference to `mgl_create_graph'
/tmp/ccPzPcZt.o: In function `mglGraph::~mglGraph()':
ml.cc:(.text._ZN8mglGraphD2Ev[_ZN8mglGraphD5Ev]+0x28): undefined reference to `mgl_use_graph'
ml.cc:(.text._ZN8mglGraphD2Ev[_ZN8mglGraphD5Ev]+0x42): undefined reference to `mgl_delete_graph'
/tmp/ccPzPcZt.o: In function `mglGraph::SetFontSize(double)':
ml.cc:(.text._ZN8mglGraph11SetFontSizeEd[_ZN8mglGraph11SetFontSizeEd]+0x2a): undefined reference to `mgl_set_font_size'
/tmp/ccPzPcZt.o: In function `mglGraph::WriteFrame(char const*, char const*)':
ml.cc:(.text._ZN8mglGraph10WriteFrameEPKcS1_[_ZN8mglGraph10WriteFrameEPKcS1_]+0x2b): undefined reference to `mgl_write_frame'
/tmp/ccPzPcZt.o: In function `mglGraph::FPlot(char const*, char const*, char const*)':
ml.cc:(.text._ZN8mglGraph5FPlotEPKcS1_S1_[_ZN8mglGraph5FPlotEPKcS1_S1_]+0x30): undefined reference to `mgl_fplot'
collect2: error: ld returned 1 exit status
"g++ -L /usr/local/lib/ -l mgl ml.o" is the same error
I encoutered exactly the same problem and managed to solve it.
If you did the installation properly as you said. Then you simply need to add -lmgl AT THE END of the line! Like this:
g++ ml.o -lmgl
As luke already had mentioned, you have a linking error, thus compiling is not affected. Here is an explanation for this behaviour:
undefined reference to symbol even when nm indicates that this symbol is present in the shared library
Hope this solved your problem.
Peter
You have a linking error. To solve this you need to link against mgl. It looks like you are trying to, but its not working.
First, I would drop the space between the l and the mgl. so
g++ -L /usr/local/lib/ -lmgl ml.o
If that doesn't work, check to see if there are any other libraries you need to link against. See if g++ is throwing errors that it cannot find mgl.
Hope that helps.
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.
I am new to boost and am trying to compile the most basic program that includes boost/asio/ssl.
I am working on ubuntu 13.10 64bit and installed the latest boost like this:
sudo apt-get install boost-all-dev
Here is the magnificent code I am trying to compile:
#include <stdio.h>
#include <boost/asio/ssl/stream.hpp>
int main(){
printf("Hi\n");
return 0;
}
I googled and googled and the few hints I was able to find suggests I use some boost library flags. So I did:
g++ my_prog.cpp -o my_prog.bin -lboost_system -lboost_thread -lpthread
and all the time I get the same error message (no matter how many -l i shove in):
/tmp/cci6dJdZ.o: In function `boost::asio::ssl::detail::openssl_init_base::do_init::do_init()':
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x2c): undefined reference to `SSL_library_init'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x31): undefined reference to `SSL_load_error_strings'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x36): undefined reference to `OPENSSL_add_all_algorithms_noconf'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x47): undefined reference to `CRYPTO_num_locks'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0xcc): undefined reference to `CRYPTO_set_locking_callback'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0xd6): undefined reference to `CRYPTO_set_id_callback'
/tmp/cci6dJdZ.o: In function `boost::asio::ssl::detail::openssl_init_base::do_init::~do_init()':
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x13): undefined reference to `CRYPTO_set_id_callback'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x1d): undefined reference to `CRYPTO_set_locking_callback'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x22): undefined reference to `ERR_free_strings'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x2c): undefined reference to `ERR_remove_state'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x31): undefined reference to `EVP_cleanup'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x36): undefined reference to `CRYPTO_cleanup_all_ex_data'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x40): undefined reference to `CONF_modules_unload'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x45): undefined reference to `ENGINE_cleanup'
/tmp/cci6dJdZ.o: In function `boost::asio::error::detail::ssl_category::message(int) const':
my_prog.cpp:(.text._ZNK5boost4asio5error6detail12ssl_category7messageEi[_ZNK5boost4asio5error6detail12ssl_category7messageEi]+0x1d): undefined reference to `ERR_reason_error_string'
collect2: error: ld returned 1 exit status
Or in short: it complaining about missing symbols like:
undefined reference to `SSL_library_init'
or:
undefined reference to `ERR_reason_error_string'.
Another funny fact is that if I change the include:
#include <boost/asio/ssl/stream.hpp>
for example to
#include <boost/asio/ssl/stream_base.hpp>
it compiles just fine (even without -lboost_system and all others..).
I spent a whole day on this and still can't for the life of me figure this out.
Any ideas guys?
In vs2013, when I include <boost/asio/ssl.hpp> I see
unresolved external symbol _CONF_modules_upload
unresolved external symbol _ERR_reason_error_string
I solved those issues by adding
libcrypto32MD.lib
in Linker/Additional Dependencies
I try to build hydra on Win 8.1 with cygwin but I get this build error when running make:
-DHAVE_MATH_H
hydra-pop3.o:hydra-pop3.c:(.text+0x697): undefined reference to `MD5_Init'
hydra-pop3.o:hydra-pop3.c:(.text+0x697): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `MD5_Init'
hydra-pop3.o:hydra-pop3.c:(.text+0x6f2): undefined reference to `MD5_Update'
hydra-pop3.o:hydra-pop3.c:(.text+0x6f2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `MD5_Update'
hydra-pop3.o:hydra-pop3.c:(.text+0x70d): undefined reference to `MD5_Update'
hydra-pop3.o:hydra-pop3.c:(.text+0x70d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `MD5_Update'
hydra-pop3.o:hydra-pop3.c:(.text+0x71e): undefined reference to `MD5_Final'
hydra-pop3.o:hydra-pop3.c:(.text+0x71e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `MD5_Final'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: hydra-pop3.o: bad reloc address 0x0 in section `.pdata'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
Makefile:51: recipe for target 'hydra' failed
make: *** [hydra] Error 1
What can be done? I could run ./configure without error, but then it failed running make.
check LIB_PATH, you need to include lib file exported "MD5_Init" function.
I have seen a lot of similar posts, but tried every trick in the book and am still struggling. Everything was working fine, but after installing/removing wireshark with some components/disselectors it all got messed up. I don't remember exactly which libraries/packages got uninstalled, but probably a lot more than I noticed.
If I create a simple main.cpp file like this one:
#include <SQLAPI.h>
int main()
{
SAConnection con;
return 0;
}
and try
g++ main.cpp -lsqlapi -ldl
it gives me the following error messages:
/usr/local/lib/libsqlapi.so: undefined reference to `dlsym'
/usr/local/lib/libsqlapi.so: undefined reference to `dlerror'
/usr/local/lib/libsqlapi.so: undefined reference to `dlopen'
/usr/local/lib/libsqlapi.so: undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
I have tried to put -ldl before -lsqlapi as some have suggested that the order is important. If I use gcc instead of g++ the error is:
/usr/bin/ld: /tmp/ccwBI4tj.o: undefined reference to symbol '__gxx_personality_v0##CXXABI_1.3'
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I am able to compile and run the file if SAConnection is removed.
I don't think it has anything to do with SQLAPI, because I experience similar problems with libboost. I don't have a small code example, but when I compile a project that was successfully compiled last week, I get the error:
/usr/bin/ld: debug/components/helloworld/HelloWorld.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
This project is using a Makefile that has been unchanged, so it has to be something on my system that is not correct. I have tried to reinstall build-essential.
Using Ubuntu 64 bit 13.10 with g++ version 4.8.1.
I have found the solution; setting the -Wl,--no-as-needed before -ldl. The new compile command is:
gcc main.cpp -lsqlapi -lstdc++ -Wl,--no-as-needed -ldl
Apparently it has something to do with recent versions of gcc/ld linking with --as-needed by default.