Error in opengl undefined reference to symbol - c++

I am running an OpenGL C++ file with fragment and vertex files.
I am on Ubuntu 18.04.
The problem is that when I link with g++ command I get errors :
my first linking command was :
g++ -o proj prog.cpp -lGL -lm
and I am getting these errors :
/tmp/ccdaDttM.o: In function `main':
prog.cpp:(.text+0x18): undefined reference to `glfwInit'
prog.cpp:(.text+0x27): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x36): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x45): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x54): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x63): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x84): undefined reference to `glfwCreateWindow'
prog.cpp:(.text+0x9f): undefined reference to `glfwGetFramebufferSize'
prog.cpp:(.text+0xd3): undefined reference to `glfwTerminate'
prog.cpp:(.text+0xe9): undefined reference to `glfwMakeContextCurrent'
prog.cpp:(.text+0xef): undefined reference to `glewExperimental'
prog.cpp:(.text+0xf5): undefined reference to `glewInit'
prog.cpp:(.text+0x22c): undefined reference to `__glewGenVertexArrays'
prog.cpp:(.text+0x241): undefined reference to `__glewGenBuffers'
prog.cpp:(.text+0x256): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x264): undefined reference to `__glewBindBuffer'
prog.cpp:(.text+0x277): undefined reference to `__glewBufferData'
prog.cpp:(.text+0x293): undefined reference to `__glewVertexAttribPointer'
prog.cpp:(.text+0x2bc): undefined reference to `__glewEnableVertexAttribArray'
prog.cpp:(.text+0x2ca): undefined reference to `__glewVertexAttribPointer'
prog.cpp:(.text+0x2f3): undefined reference to `__glewEnableVertexAttribArray'
prog.cpp:(.text+0x301): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x314): undefined reference to `glfwWindowShouldClose'
prog.cpp:(.text+0x326): undefined reference to `glfwPollEvents'
prog.cpp:(.text+0x368): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x38a): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x39d): undefined reference to `glfwSwapBuffers'
prog.cpp:(.text+0x3a9): undefined reference to `__glewDeleteVertexArrays'
prog.cpp:(.text+0x3be): undefined reference to `__glewDeleteBuffers'
prog.cpp:(.text+0x3d1): undefined reference to `glfwTerminate'
/tmp/ccdaDttM.o: In function `Shader::Shader(char const*, char const*)':
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x27b): undefined reference to `__glewCreateShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x28f): undefined reference to `__glewShaderSource'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x2af): undefined reference to `__glewCompileShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x2c0): undefined reference to `__glewGetShaderiv'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x2e7): undefined reference to `__glewGetShaderInfoLog'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x347): undefined reference to `__glewCreateShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x35b): undefined reference to `__glewShaderSource'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x37b): undefined reference to `__glewCompileShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x38c): undefined reference to `__glewGetShaderiv'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x3b3): undefined reference to `__glewGetShaderInfoLog'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x413): undefined reference to `__glewCreateProgram'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x427): undefined reference to `__glewAttachShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x443): undefined reference to `__glewAttachShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x45f): undefined reference to `__glewLinkProgram'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x473): undefined reference to `__glewGetProgramiv'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x49d): undefined reference to `__glewGetProgramInfoLog'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x500): undefined reference to `__glewDeleteShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x511): undefined reference to `__glewDeleteShader'
/tmp/ccdaDttM.o: In function `Shader::Use()':
prog.cpp:(.text._ZN6Shader3UseEv[_ZN6Shader3UseEv]+0xf): undefined reference to `__glewUseProgram'
collect2: error: ld returned 1 exit status
When I googled, I found this post : undefined reference to `__glewCreateShader`
and according to the post, I changed the command to :
g++ -o proj prog.cpp -lGLEW -lm
The long list of errors is reduced but still :
/usr/bin/ld: /tmp/ccSaE0MX.o: undefined reference to symbol 'glDrawArrays'
//usr/lib/x86_64-linux-gnu/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I viewed several posts and they almost say the same thing
OpenGL library not linking
The command I tried :
g++ -o proj prog.cpp -lGLEW -lm -lGLU -lglut
g++ -o proj prog.cpp -lGL -lGLEW -lm
g++ -o proj prog.cpp -lGLEW -lGL -lm
g++ -o proj prog.cpp -lGLEW -lopengl32 -lm
g++ prog.cpp -lGL -lGLU -lGLEW -lGLFW -lm
g++ prog.cpp -lGL -lGLU -lGLEW -lglut -lm -o proj
include :
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "Shader.h"
Update :
here is what I am getting now
g++ -o proj sample.cpp libglut.a -lGL -lm
/usr/bin/ld: libglut.a(glut_event.o): undefined reference to symbol 'XWithdrawWindow'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Please tell me what am I doing wrong.
Thanks

Related

Include openssl/libcrypto statically

I am trying to compile an app with static curl and i it seems OpenSSL is not properly linked.
COMPILE CMD:
$(CXX) $(CXXFLAGS) program1.cpp /opt/curl-7.62.0/lib/libcurl.a /opt/openssl-1.1.1a/lib/libcrypto.a -o program1 -L/opt/curl-7.62.0/ -L/opt/openssl-1.1.1a/ -Wwrite-strings -fpermissive -static-libstdc++ -lcrypto -lssl -lcurl -Wl,-Bstatic -lidn2 -lrt -lz -Wl,-Bdynamic -ldl -lpthread
CURL:
rm -rf /opt/curl-7.62.0/*; ./configure --prefix=/opt/curl-7.62.0 --with-pic --disable-shared --enable-static --with-libidn=/opt/libidn2-2.0.4 --with-ssl=/opt/openssl-1.1.1a --without-librtmp --without-gnutls --without-nss --without-libssh2 --with-zlib=/opt/zlib-1.2.11 --without-winidn --disable-rtsp --disable-ldap --disable-ldaps --disable-ipv6 LIBS=-ldl; make -j 8; make install; ls -al /opt/curl-7.62.0/;
OPENSSL :
./config --prefix=/opt/openssl-1.1.1a -fPIC -static; make; make install;
Errors :
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_sha256sum':
openssl.c:(.text+0x13c): undefined reference to `EVP_MD_CTX_new'
openssl.c:(.text+0x177): undefined reference to `EVP_MD_CTX_free'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_md5sum':
openssl.c:(.text+0x1cc): undefined reference to `EVP_MD_CTX_new'
openssl.c:(.text+0x207): undefined reference to `EVP_MD_CTX_free'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_version':
openssl.c:(.text+0xb54): undefined reference to `OpenSSL_version_num'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `servercert':
openssl.c:(.text+0x19d0): undefined reference to `X509_get0_notBefore'
openssl.c:(.text+0x1a2c): undefined reference to `X509_get0_notAfter'
openssl.c:(.text+0x1b29): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x1b7f): undefined reference to `OPENSSL_sk_value'
openssl.c:(.text+0x1c77): undefined reference to `X509_get_X509_PUBKEY'
openssl.c:(.text+0x1caf): undefined reference to `X509_get_X509_PUBKEY'
openssl.c:(.text+0x1f22): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x1fa9): undefined reference to `OPENSSL_sk_value'
openssl.c:(.text+0x207e): undefined reference to `X509_get_version'
openssl.c:(.text+0x21f4): undefined reference to `X509_get_X509_PUBKEY'
openssl.c:(.text+0x2272): undefined reference to `X509_get0_extensions'
openssl.c:(.text+0x227d): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x22f1): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x2303): undefined reference to `OPENSSL_sk_value'
openssl.c:(.text+0x2673): undefined reference to `X509_get0_notBefore'
openssl.c:(.text+0x26cb): undefined reference to `X509_get0_notAfter'
openssl.c:(.text+0x2755): undefined reference to `EVP_PKEY_get0_RSA'
openssl.c:(.text+0x276f): undefined reference to `RSA_get0_key'
openssl.c:(.text+0x2ac5): undefined reference to `ASN1_STRING_get0_data'
openssl.c:(.text+0x2b6c): undefined reference to `EVP_PKEY_get0_DSA'
openssl.c:(.text+0x2b8c): undefined reference to `DSA_get0_pqg'
openssl.c:(.text+0x2b9e): undefined reference to `DSA_get0_key'
openssl.c:(.text+0x2c44): undefined reference to `EVP_PKEY_get0_DH'
openssl.c:(.text+0x2c64): undefined reference to `DH_get0_pqg'
openssl.c:(.text+0x2c76): undefined reference to `DH_get0_key'
openssl.c:(.text+0x2d15): undefined reference to `ASN1_STRING_get0_data'
openssl.c:(.text+0x2d3d): undefined reference to `ASN1_STRING_get0_data'
openssl.c:(.text+0x32aa): undefined reference to `ASN1_STRING_get0_data'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_step2':
openssl.c:(.text+0x3461): undefined reference to `SSL_get_client_random'
openssl.c:(.text+0x3476): undefined reference to `SSL_SESSION_get_master_key'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_step1':
openssl.c:(.text+0x3f51): undefined reference to `TLS_client_method'
openssl.c:(.text+0x40b3): undefined reference to `SSL_CTX_set_options'
openssl.c:(.text+0x545c): undefined reference to `OPENSSL_sk_pop_free'
openssl.c:(.text+0x55fe): undefined reference to `OPENSSL_sk_pop'
openssl.c:(.text+0x5640): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x566c): undefined reference to `OPENSSL_sk_pop_free'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'main' failed
....
What could it be?
Thank you.
I'm fairly certain that libcurl depends on the SSL/Crypto binaries, not the other way around.
And I believe the gnu linker doesn't "go back" in the library list to resolve missing symbols, only forward in the list. Hence, this order of library includes:
-lcrypto -lssl -lcurl
Should be this:
-lcurl -lssl -lcrypto
Another option - redundantly append -lcrypto -lssl and to the end of the build line. That is:
$(CXX) $(CXXFLAGS) program1.cpp /opt/curl-7.62.0/lib/libcurl.a /opt/openssl-1.1.1a/lib/libcrypto.a -o program1 -L/opt/curl-7.62.0/ -L/opt/openssl-1.1.1a/ -Wwrite-strings -fpermissive -static-libstdc++ -lcrypto -lssl -lcurl -Wl,-Bstatic -lidn2 -lrt -lz -Wl,-Bdynamic -ldl -lpthread -lcrypto -lssl
If any of the above works, you can experiment with link library order.

Can't link OpenSSL libraries properly with Mingw on OS X

I have some RSA code, however, I can't get it to compile & link properly.
build.sh:
x86_64-w64-mingw32-g++ rsa.cpp -L/usr/local/opt/openssl/lib -lcrypto -lssl -I/usr/local/opt/openssl/include/ -static-libstdc++ -static-libgcc -o main.exe
result:
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0xe6): undefined reference to `BIO_new_mem_buf'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0xef): undefined reference to `BIO_f_base64'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0xf7): undefined reference to `BIO_new'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x10b): undefined reference to `BIO_push'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x130): undefined reference to `BIO_read'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x146): undefined reference to `BIO_free_all'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x177): undefined reference to `EVP_PKEY_new'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x193): undefined reference to `EVP_PKEY_assign'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x198): undefined reference to `EVP_MD_CTX_create'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x1a5): undefined reference to `EVP_sha256'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x1c7): undefined reference to `EVP_DigestVerifyInit'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x1f1): undefined reference to `EVP_DigestUpdate'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x218): undefined reference to `EVP_DigestVerifyFinal'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x234): undefined reference to `EVP_MD_CTX_cleanup'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x254): undefined reference to `EVP_MD_CTX_cleanup'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x26e): undefined reference to `EVP_MD_CTX_cleanup'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x2ac): undefined reference to `BIO_new_mem_buf'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x2da): undefined reference to `PEM_read_bio_RSA_PUBKEY'
collect2: error: ld returned 1 exit status
both libcrypto.a and libssl.a exist in /usr/local/opt/openssl/lib. I'm building on OS X mingw compiler a windows application.
EDIT: objdump -d /usr/local/opt/openssl/lib/libcrypto.a > ~/libcrypto.a.txt
EDIT2: Tried grouping: x86_64-w64-mingw32-g++ rsa.cpp -L/usr/local/opt/openssl/lib -Wl,--start-group -lcrypto -lssl -Wl,--end-group -lws2_32 -lwsock32 -liphlpapi -I/usr/local/opt/openssl/include/ -static-libstdc++ -static-libgcc -o main.exe, same result

Getting unexpected "undefined reference to" errors when compiling with a static library

I've been trying to make a static library out of this: https://github.com/onlinecity/cpp-smpp , as I'd like to make a single file executable that uses it.
So far I have gone into src/smpp/ and created the .o files with:
g++-5 -c *.cpp -std=c++11 -I.
Then made them into an .a file with:
ar rvs libsmpp.a *.o
Then I'm trying to compile a small main.cpp file that uses the library with this:
g++-5 main.cpp -I/usr/local/include -static libsmpp.a -lboost_system -lboost_regex -lboost_date_time -lpthread -lm -lglog -lgflags -std=c++11
And I get some undefined reference errors:
/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a(condition_variable.o): In function `std::condition_variable::~condition_variable()':
(.text._ZNSt18condition_variableD2Ev+0x1): undefined reference to `pthread_cond_destroy'
/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a(condition_variable.o): In function `std::condition_variable::wait(std::unique_lock<std::mutex>&)':
(.text._ZNSt18condition_variable4waitERSt11unique_lockISt5mutexE+0x8): undefined reference to `pthread_cond_wait'
libsmpp.a(smppclient.o): In function `smpp::SmppClient::sendPdu(smpp::PDU&)':
smppclient.cpp:(.text+0x22a1): undefined reference to `google::LogMessage::LogMessage(char const*, int)'
smppclient.cpp:(.text+0x22b0): undefined reference to `google::LogMessage::stream()'
smppclient.cpp:(.text+0x22d4): undefined reference to `google::LogMessage::~LogMessage()'
smppclient.cpp:(.text+0x2534): undefined reference to `google::LogMessage::~LogMessage()'
libsmpp.a(smppclient.o): In function `smpp::SmppClient::readPdu(bool const&)':
smppclient.cpp:(.text+0x29d8): undefined reference to `google::LogMessage::LogMessage(char const*, int)'
smppclient.cpp:(.text+0x29e7): undefined reference to `google::LogMessage::stream()'
smppclient.cpp:(.text+0x2a0b): undefined reference to `google::LogMessage::~LogMessage()'
smppclient.cpp:(.text+0x2a48): undefined reference to `google::LogMessage::~LogMessage()'
libsmpp.a(smppclient.o): In function `boost::asio::detail::posix_event::~posix_event()':
smppclient.cpp:(.text._ZN5boost4asio6detail11posix_eventD2Ev[_ZN5boost4asio6detail11posix_eventD5Ev]+0x14): undefined reference to `pthread_cond_destroy'
libsmpp.a(smppclient.o): In function `boost::asio::detail::posix_event::posix_event()':
smppclient.cpp:(.text._ZN5boost4asio6detail11posix_eventC2Ev[_ZN5boost4asio6detail11posix_eventC5Ev]+0x2e): undefined reference to `pthread_cond_init'
libsmpp.a(smppclient.o): In function `void boost::asio::detail::posix_event::wait<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
smppclient.cpp:(.text._ZN5boost4asio6detail11posix_event4waitINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[_ZN5boost4asio6detail11posix_event4waitINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_]+0x5f): undefined reference to `pthread_cond_wait'
libsmpp.a(timeformat.o): In function `boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::ostream&)':
timeformat.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[_ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo]+0x33): undefined reference to `boost::gregorian::greg_month::as_short_string() const'
timeformat.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[_ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo]+0x56): undefined reference to `boost::gregorian::greg_month::as_long_string() const'
collect2: error: ld returned 1 exit status
It compiles fine when I link to a dynamic version of the smpp library, although that's made using the cmake files included with the smpp lib. I didn't know how to modify them to output a static library, so I just used the g++ command at the top, and added the libraries listed in them (like glog) in the main.cpp compile command.
The "undefined reference to google::logMessage" seems especially strange, as I'm pretty sure thats part of glog, which is definitely loaded and included in the smppclient.cpp file itself.
Any ideas? Thanks.

Why am I getting such error message in Installing Package?

I am currently running Ubuntu 12.04.
I am looking to install This Package.
I have already installed packages:
'fftw2', 'fftw-dev', 'fftw-doc', 'fftw-3.3.4'
However, when I try to root#ubuntu:~/spectrum-master# make:
cc -lm -lasound -L/usr/lib/x86_64-linux-gnu -lSDL -lfftw3f -lm spectrum.o mmap_file.o pcm.o wav.o alsa.o window.o stft.o cqt.o trans.o -o spectrum
spectrum.o: In function handle_events': /home/userKum/spectrum-master/spectrum.c:27: undefined reference toSDL_PollEvent'
spectrum.o: In function srgb': /home/userKum/spectrum-master/spectrum.c:78: undefined reference to__powf_finite'
/home/userKum/spectrum-master/spectrum.c:76: undefined reference to __powf_finite' /home/userKum/spectrum-master/spectrum.c:77: undefined reference to__powf_finite'
spectrum.o: In function main': /home/userKum/spectrum-master/spectrum.c:126: undefined reference toSDL_Init'
/home/userKum/spectrum-master/spectrum.c:127: undefined reference to SDL_SetVideoMode' /home/userKum/spectrum-master/spectrum.c:143: undefined reference toSDL_WM_SetCaption'
/home/userKum/spectrum-master/spectrum.c:144: undefined reference to SDL_EnableKeyRepeat' /home/userKum/spectrum-master/spectrum.c:199: undefined reference to__log10f_finite'
/home/userKum/spectrum-master/spectrum.c:157: undefined reference to SDL_Flip' /home/userKum/spectrum-master/spectrum.c:158: undefined reference toSDL_Delay'
alsa.o: In function write_alsa': /home/userKum/spectrum-master/alsa.c:71: undefined reference tosnd_pcm_writei'
/home/userKum/spectrum-master/alsa.c:72: undefined reference to snd_pcm_prepare' alsa.o: In functionread_alsa':
/home/userKum/spectrum-master/alsa.c:54: undefined reference to snd_pcm_readi' /home/userKum/spectrum-master/alsa.c:55: undefined reference tosnd_pcm_prepare'
alsa.o: In function close_alsa': /home/userKum/spectrum-master/alsa.c:26: undefined reference tosnd_pcm_drain'
/home/userKum/spectrum-master/alsa.c:27: undefined reference to snd_pcm_close' alsa.o: In functionopen_alsa_read':
/home/userKum/spectrum-master/alsa.c:92: undefined reference to snd_pcm_hw_params_sizeof' /home/userKum/spectrum-master/alsa.c:92: undefined reference tosnd_pcm_hw_params_sizeof'
/home/userKum/spectrum-master/alsa.c:94: undefined reference to snd_pcm_open' /home/userKum/spectrum-master/alsa.c:100: undefined reference tosnd_pcm_hw_params_any'
/home/userKum/spectrum-master/alsa.c:107: undefined reference to snd_pcm_hw_params_set_access' /home/userKum/spectrum-master/alsa.c:114: undefined reference tosnd_pcm_hw_params_set_format'
/home/userKum/spectrum-master/alsa.c:121: undefined reference to snd_pcm_hw_params_set_rate_resample' /home/userKum/spectrum-master/alsa.c:130: undefined reference tosnd_pcm_hw_params_set_rate_min'
/home/userKum/spectrum-master/alsa.c:109: undefined reference to snd_pcm_close' /home/userKum/spectrum-master/alsa.c:137: undefined reference tosnd_pcm_hw_params'
/home/userKum/spectrum-master/alsa.c:144: undefined reference to snd_pcm_hw_params_get_rate' /home/userKum/spectrum-master/alsa.c:151: undefined reference tosnd_pcm_hw_params_get_channels'
alsa.o: In function open_alsa_write': /home/userKum/spectrum-master/alsa.c:177: undefined reference tosnd_pcm_hw_params_sizeof'
/home/userKum/spectrum-master/alsa.c:177: undefined reference to snd_pcm_hw_params_sizeof' /home/userKum/spectrum-master/alsa.c:179: undefined reference tosnd_pcm_open'
/home/userKum/spectrum-master/alsa.c:185: undefined reference to snd_pcm_hw_params_any' /home/userKum/spectrum-master/alsa.c:192: undefined reference tosnd_pcm_hw_params_set_access'
/home/userKum/spectrum-master/alsa.c:199: undefined reference to snd_pcm_hw_params_set_format' /home/userKum/spectrum-master/alsa.c:206: undefined reference tosnd_pcm_hw_params_set_rate_resample'
/home/userKum/spectrum-master/alsa.c:213: undefined reference to snd_pcm_hw_params_set_rate_near' /home/userKum/spectrum-master/alsa.c:218: undefined reference tosnd_pcm_hw_params_set_channels_near'
/home/userKum/spectrum-master/alsa.c:223: undefined reference to snd_pcm_hw_params' /home/userKum/spectrum-master/alsa.c:194: undefined reference tosnd_pcm_close'
window.o: In function sinc': /home/userKum/spectrum-master/window.c:14: undefined reference tosinf'
window.o: In function hann': /home/userKum/spectrum-master/window.c:24: undefined reference tocosf'
window.o: In function hamming': /home/userKum/spectrum-master/window.c:29: undefined reference tocosf'
window.o: In function sinc': /home/userKum/spectrum-master/window.c:14: undefined reference tosinf'
window.o: In function gauss': /home/userKum/spectrum-master/window.c:38: undefined reference to__expf_finite'
stft.o: In function free_stft': /home/userKum/spectrum-master/stft.c:44: undefined reference tofftwf_destroy_plan'
stft.o: In function get_stft': /home/userKum/spectrum-master/stft.c:38: undefined reference tocabsf'
stft.o: In function create_stft': /home/userKum/spectrum-master/stft.c:66: undefined reference tofftwf_plan_dft_r2c_1d'
stft.o: In function slide_stft': /home/userKum/spectrum-master/stft.c:31: undefined reference tofftwf_execute'
cqt.o: In function get_cqt': /home/userKum/spectrum-master/cqt.c:33: undefined reference tocabsf'
cqt.o: In function free_cqt': /home/userKum/spectrum-master/cqt.c:47: undefined reference tofftwf_destroy_plan'
cqt.o: In function create_cqt': /home/userKum/spectrum-master/cqt.c:65: undefined reference to__logf_finite'
/home/userKum/spectrum-master/cqt.c:65: undefined reference to __expf_finite' /home/userKum/spectrum-master/cqt.c:66: undefined reference to__log2_finite'
/home/userKum/spectrum-master/cqt.c:87: undefined reference to fftwf_plan_dft_1d' /home/userKum/spectrum-master/cqt.c:98: undefined reference tocexpf'
/home/userKum/spectrum-master/cqt.c:103: undefined reference to fftwf_execute' /home/userKum/spectrum-master/cqt.c:57: undefined reference tocabsf'
/home/userKum/spectrum-master/cqt.c:57: undefined reference to cabsf' /home/userKum/spectrum-master/cqt.c:115: undefined reference tocabsf'
/home/userKum/spectrum-master/cqt.c:117: undefined reference to cabsf' /home/userKum/spectrum-master/cqt.c:117: undefined reference tocabsf'
/home/userKum/spectrum-master/cqt.c:57: undefined reference to __powf_finite' /home/userKum/spectrum-master/cqt.c:139: undefined reference tofftwf_destroy_plan'
/home/userKum/spectrum-master/cqt.c:146: undefined reference to fftwf_plan_dft_r2c_1d' cqt.o: In functionslide_cqt':
/home/userKum/spectrum-master/cqt.c:30: undefined reference to `fftwf_execute'
collect2: ld returned 1 exit status
make: *** [spectrum] Error 1
I have no idea what these undefined reference is all about...... It looks it is missing a linkage to '-lasound' during compilation. What should I do so that I can solve this issue?
As requested by some of the viewer, the MakeFile is as follows:
CFLAGS = -g -D_GNU_SOURCE=1 -W -Wall -O3 -std=c99 -fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math -fcx-limited-range -fsingle-precision-constant $(shell sdl-config --cflags) $(shell pkg-config fftw3f --cflags)
LDFLAGS = -lm -lasound $(shell sdl-config --libs) $(shell pkg-config fftw3f --libs)
all: spectrum
clean:
rm -f spectrum *.o
spectrum: spectrum.o mmap_file.o pcm.o wav.o alsa.o window.o stft.o cqt.o trans.o
Another classic case of "libraries need to come after the objects":
Your libraries, defined by
LDFLAGS = -lm -lasound $(shell sdl-config --libs) $(shell pkg-config fftw3f --libs)
Given that (according to here) the rule for linking is:
$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)
I would expect that
LDLIBS = -lm -lasound $(shell sdl-config --libs) $(shell pkg-config fftw3f --libs)
would do the trick, although I prefer to actually write my own linker line, as inevitably I end up wanting to know exactly what is linked...
(Unix linkers are rather simplistic in their dealing with libraries, so if you list -lsomething x.o to the linker, the linker will not take anything from -lsomething, and complaim that somethingFunc1(which can be found in libsomething.a) is missing because it wasn't found AFTER x.o.

linking c++ libraries on Linux

I'm running the following command:
g++ -m32 testLogin.cpp -L/root/c++/libs -ldvrnetsdk -o testLoginO -lpthread -lasound
the result:
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_channels'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutex_trylock'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_readi'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_access'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_strerror'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutexattr_settype'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_rate'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_close'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_malloc'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_period_size'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutex_timedlock'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutexattr_destroy'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_drain'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_free'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_create'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_open'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_format'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_writei'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutexattr_init'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_any'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_prepare'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
The first thing I did after this error was to include the libraries -lpthread -lasound, I also worked on the parameters order but did not work. I appriciate any help.
did you try with just -pthread as the linker flag...sometimes it does notw ork with -lpthread...
This should work
g++ -m32 testLogin.cpp -L/root/c++/libs -ldvrnetsdk -pthread -lasound
With gcc, ordering of linking does matter.
So, try with different order.
g++ -m32 testLogin.cpp -L/root/c++/libs -lpthread -lasound -ldvrnetsdk -o testLoginO
See this question for order: Why does the order in which libraries are linked sometimes cause errors in GCC?
Alternatively, you can use start-group option.
gcc -m32 testLogin.cpp -L/root/c++/libs -Wl,--start-group -lpthread -lasound -ldvrnetsdk -Wl,--end-group -o testLoginO
Edit: As you still get the error, use nm on strings on your library and check if the symbols for which linker error is given are in the library or not. Check for library version. You might be on 64-bit kernel.