how to compile project include libcurl "undefined reference" - c++

I'm using compile downloaded source code and try to make my c++ project but these error appear.
user1#ubuntu:~$ make
g++ -std=c++0x -g -Wall -Werror -L/home/user1/project0/libcurl/lib/libcurl.a -I/home/user1/proj/libcurl/include -c my-curl.cpp -o curl.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/project0/libcurl/lib/libcurl.a -I/home/user1/proj/libcurl/include -c main.cpp -o main.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/project0/libcurl/lib/libcurl.a -I/home/user1/proj/libcurl/include -o my-curl-app my-curl.o main.o
my-curl.o: In function `CCurlDownloader::start_download()':
~/my-curl.cpp:22: undefined reference to `curl_easy_init'
~/my-curl.cpp:27: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:28: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:29: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:30: undefined reference to `curl_easy_perform'
~/my-curl.cpp:53: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [my-curl-app] Error 1
and i'm changed -L option to specified directory and add -lcurl for specified lib and result is.
user1#ubuntu:~/project0/my-curl$ make
g++ -std=c++0x -g -Wall -Werror -L/home/user1/practics/libcurl/lib -lcurl -I/home/user1/practics/libcurl/include -c my-curl.cpp -o my-curl.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/practics/libcurl/lib -lcurl -I/home/user1/practics/libcurl/include -c main.cpp -o main.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/practics/libcurl/lib -lcurl -I/home/user1/practics/libcurl/include -o my-curl-cpp my-curl.o main.o
my-curl.o: In function `CCurlDownloader::start_download()':
~/my-curl.cpp:22: undefined reference to `curl_easy_init'
~/my-curl.cpp:27: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:28: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:29: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:30: undefined reference to `curl_easy_perform'
~/my-curl.cpp:53: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [bb-cppurl] Error 1
I and try curl-config to link libs but result still be the same.
user1#atom-linux-server:~/my-curl$ make
g++ -std=c++0x -g -Wall -Werror `/home/user1/project0/libcurl/bin/curl-config --libs` `/home/user1/project0/libcurl/bin/curl-config --cflags` -c my-curl.cpp -o my-curl.o
g++ -std=c++0x -g -Wall -Werror `/home/user1/project0/libcurl/bin/curl-config --libs` `/home/user1/project0/libcurl/bin/curl-config --cflags` -c main.cpp -o main.o
g++ -std=c++0x -g -Wall -Werror `/home/user1/project0/libcurl/bin/curl-config --libs` `/home/user1/project0/libcurl/bin/curl-config --cflags` -o my-curl-app my-curl.o main.o
my-curl.o: In function `CCurlDownloader::start_download()':
~/my-curl.cpp:22: undefined reference to `curl_easy_init'
~/my-curl.cpp:27: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:28: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:29: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:30: undefined reference to `curl_easy_perform'
~/my-curl.cpp:53: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [bb-cppurl] Error 1

You're using the build tools wrong.
1 - the -L option should specify a directory
2 - there's no -l (lowercase L) option to specify which lib to link with (perhaps from the directory -L identifies)

I move
-L/home/user1/practics/libcurl/lib -lcurl
to the tail of command
g++ -std=c++0x -g -Wall -Werror -I/home/user1/practics/libcurl/include -o my-curl-cpp my-curl.o main.o -L/home/user1/practics/libcurl/lib -lcurl
and it works.

Related

undefined reference to `get_driver_instance - c++ mysql connector

Questions asked on stackoverflow about this question,have not been able to help me, this is complete error:
/usr/bin/ld: /tmp/ccgpX9K3.o: in function `connectDB(sql::Connection*)':
/home/erasmoh/sockets_c++/src/server.cpp:128: undefined reference to `get_driver_instance'
collect2: error: ld returned 1 exit status
i have tried this commands:
sudo g++ -Wall -I/usr/include/cppconn -o server server.cpp -L/usr/lib -lmysqlcppconn
g++ -g -o0 -I/usr/local/include -I/usr/local/boost/include -c server.cpp -o server.o
g++ -g -o0 -L/usr/local/lib -L/usr/local/mysql/lib server.o -o server -lmysqlcppconn
i have tried other ways to do it, creating a shared library as well, but, i getting the same error.

C ++ warning: relocation against ... undefined reference to

I've a problem compiling my C++ project using a makefile.
The structure of the project is like:
gui/:
Basicshape.cpp / .h
Functionable.cpp / .h
logic/:
Matrix.cpp/ .h
Cell.cpp/ .h
Item.cpp / .h
Position.cpp / .h
main.cpp
makefile
Here's the content of the makefile:
FLAGS=--std='c++20' -Wall -Wextra -Wpedantic -lfltk
all:CandyCrush
CandyCrush: main.o Matrice.o Cell.o Item.o Position.o BasicShape.o Functionable.o
g++ main.o Matrice.o Cell.o Item.o Position.o BasicShape.o Functionable.o -o CandyCrush
Cell.o: logic/Cell.h logic/Cell.cpp
g++ $(FLAGS) -c logic/Cell.cpp -o Cell.o
Item.o: logic/Item.h logic/Item.cpp
g++ $(FLAGS) -c logic/Item.cpp -o Item.o
Position.o: logic/Position.h logic/Position.cpp
g++ $(FLAGS) -c logic/Position.cpp -o Position.o
Matrice.o: logic/Matrice.h logic/Matrice.cpp
g++ $(FLAGS) -c logic/Matrice.cpp -o Matrice.o
BasicShape.o: gui/BasicShapes.h gui/BasicShapes.cpp
g++ $(FLAGS) -c gui/BasicShapes.cpp -o BasicShape.o
Functionable.o: gui/Functionable.h gui/Functionable.cpp
g++ $(FLAGS) -c gui/Functionable.cpp -o Functionable.o
main.o: main.cpp
g++ $(FLAGS) -c main.cpp -o main.o
clear:
rm *.o
I know it can be shortened but for debugging purposes and the fact than I'm still learning I prefer keeping this structure.
By typing make in my terminal, I've this error and I'm not sure why :
/usr/bin/ld: BasicShape.o: warning: relocation against `_ZTV9Rectangle' in read-only section `.text'
/usr/bin/ld: BasicShape.o: in function `Rectangle::Rectangle(Point, int, int, unsigned int, unsigned int)':
BasicShapes.cpp:(.text+0xdd): undefined reference to `vtable for Rectangle'
/usr/bin/ld: BasicShapes.cpp:(.text+0xf3): undefined reference to `vtable for Rectangle'
/usr/bin/ld: BasicShape.o: in function `Circle::Circle(Point, int, unsigned int, unsigned int)':
BasicShapes.cpp:(.text+0x225): undefined reference to `vtable for Circle'
/usr/bin/ld: BasicShapes.cpp:(.text+0x23b): undefined reference to `vtable for Circle'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [makefile:6: CandyCrush] Error 1

SDL2 Msys2 Windows X64 build

Trying to build SDL2-2.0.14 on Windows with latest MSYS.
If i try to build with the minimal makefile in the root SDL directory i get the following error:
cc -g -O2 -I./include -c -o src/timer/dummy/SDL_systimer.o src/timer/dummy/SDL_systimer.c
cc -g -O2 -I./include -c -o src/video/SDL_RLEaccel.o src/video/SDL_RLEaccel.c
cc -g -O2 -I./include -c -o src/video/SDL_blit.o src/video/SDL_blit.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_0.o src/video/SDL_blit_0.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_1.o src/video/SDL_blit_1.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_A.o src/video/SDL_blit_A.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_N.o src/video/SDL_blit_N.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_auto.o src/video/SDL_blit_auto.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_copy.o src/video/SDL_blit_copy.c
cc -g -O2 -I./include -c -o src/video/SDL_blit_slow.o src/video/SDL_blit_slow.c
cc -g -O2 -I./include -c -o src/video/SDL_bmp.o src/video/SDL_bmp.c
cc -g -O2 -I./include -c -o src/video/SDL_clipboard.o src/video/SDL_clipboard.c
cc -g -O2 -I./include -c -o src/video/SDL_egl.o src/video/SDL_egl.c
src/video/SDL_egl.c:25:2: error: #error this should be not defined
25 | #error this should be not defined
| ^~~~~
In file included from src/video/SDL_egl_c.h:28,
from src/video/SDL_egl.c:36:
./include/SDL_egl.h:29:10: fatal error: EGL/egl.h: No such file or directory
29 | #include <EGL/egl.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: src/video/SDL_egl.o] Error 1
Solved it removing OPENGL support in include/SDL_config_windows.h:269:
#ifndef SDL_VIDEO_OPENGL_EGL
/* #define SDL_VIDEO_OPENGL_EGL 1 commented for wind64 build */
#endif
Now i've got the libSDL.a file, but if i try to build a test from the test folder:
Alessandro#DESKTOP-954PK5R MINGW64 /c/WORK/sdl_latest/SDL2-2.0.14/test
$ cc -g testkeys.c ../libSDL.a -I../include -o testkeys.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\ccSosm3W.o: in function `SDL_main':
C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:28: undefined reference to `SDL_LogSetPriority'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:30: undefined reference to `SDL_Init'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:31: undefined reference to `SDL_GetError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:31: undefined reference to `SDL_LogError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:35: undefined reference to `SDL_GetScancodeName'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:35: undefined reference to `SDL_Log'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\WORK\sdl_latest\SDL2-2.0.14\test/testkeys.c:38: undefined reference to `SDL_Quit'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
Do i have to link something else?

g++ - linking stage (-L flag) not working

I am new to C++ and am trying to figure out where in the compiling process my error is. Apologies, if this question is unclear, I'm not sure what information to provide.
Reference information: The directory "mbedtls/lib/" contains two .a (archive) files, "libmbedtls_SGX_t.a" and "libmbedtls_SGX_u.a".
I am using a Makefile, which runs the following commands in order. The commands seem to run error free:
cc -m64 -O2 -fPIC -Wno-attributes -IApp -I/opt/intel/sgxsdk/include -Imbedtls/include -DNDEBUG -UEDEBUG -UDEBUG -c App/Enclave_u.c -o App/Enclave_u.o
g++ -m64 -O2 -fPIC -Wno-attributes -IApp -I/opt/intel/sgxsdk/include -Imbedtls/include -DNDEBUG -UEDEBUG -UDEBUG -std=c++11 -c App/App.cpp -o App/App.o
g++ -m64 -O2 -fPIC -Wno-attributes -IApp -I/opt/intel/sgxsdk/include -Imbedtls/include -DNDEBUG -UEDEBUG -UDEBUG -std=c++11 -c App/sgx_utils/sgx_utils.cpp -o App/sgx_utils/sgx_utils.o
After running those commands, it runs this command:
g++ App/Enclave_u.o App/App.o App/sgx_utils/sgx_utils.o -o app -m64 -O2 -L/opt/intel/sgxsdk/lib64 -lsgx_urts_sim -lpthread -Lmbedtls/lib/ -lsgx_uae_service_sim
However, this command produces an error:
App/Enclave_u.o: In function `Enclave_ocall_print_string':
Enclave_u.c:(.text+0x9): undefined reference to `ocall_print_string'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_free':
Enclave_u.c:(.text+0x28): undefined reference to `ocall_mbedtls_net_free'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_recv_timeout':
Enclave_u.c:(.text+0x54): undefined reference to `ocall_mbedtls_net_recv_timeout'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_send':
Enclave_u.c:(.text+0x71): undefined reference to `ocall_mbedtls_net_send'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_recv':
Enclave_u.c:(.text+0x91): undefined reference to `ocall_mbedtls_net_recv'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_usleep':
Enclave_u.c:(.text+0xa8): undefined reference to `ocall_mbedtls_net_usleep'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_set_nonblock':
Enclave_u.c:(.text+0xc9): undefined reference to `ocall_mbedtls_net_set_nonblock'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_set_block':
Enclave_u.c:(.text+0xe9): undefined reference to `ocall_mbedtls_net_set_block'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_accept':
Enclave_u.c:(.text+0x119): undefined reference to `ocall_mbedtls_net_accept'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_bind':
Enclave_u.c:(.text+0x144): undefined reference to `ocall_mbedtls_net_bind'
App/Enclave_u.o: In function `Enclave_ocall_mbedtls_net_connect':
Enclave_u.c:(.text+0x164): undefined reference to `ocall_mbedtls_net_connect'
collect2: error: ld returned 1 exit status
Makefile:184: recipe for target 'app' failed
I don't know why this error is being produced. My last command includes the flag -Lmbedtls/lib/ which should resolve these undefined references by linking the archive files (specifically - libmbedtls_SGX_u.a) to the executable. However, clearly this is not happening.
Do I need to link the archive files earlier in the compile process? I.e - instead of using the flag -Lmbedtls/lib/ in the final g++ command, should I be using it in both of the previous g++ commands?
Update: Adding the flag -Lmbedtls/lib/ to the previous 2 g++ commands (the ones that generated App.o and sgx_utils.o) did not change anything. The error remains.
As has been mentioned in the comment, only specifying a directory with -L without specifying the name of a library in that directory is useless.
So you have to additionally specify the library names with -l.
So instead of:
g++ App/Enclave_u.o App/App.o App/sgx_utils/sgx_utils.o -o app -m64 -O2 \
-L/opt/intel/sgxsdk/lib64 -lsgx_urts_sim -lpthread \
-Lmbedtls/lib/ \
-lsgx_uae_service_sim
Use:
g++ App/Enclave_u.o App/App.o App/sgx_utils/sgx_utils.o -o app -m64 -O2 \
-L/opt/intel/sgxsdk/lib64 -lsgx_urts_sim -lpthread \
-Lmbedtls/lib/ -lmbedtls_SGX_t -lmbedtls_SGX_u \
-lsgx_uae_service_sim

undefined reference to `boost::system::generic_category()' [duplicate]

This question already has an answer here:
g++ undefined reference to `boost::system::system_category()'
(1 answer)
Closed 9 years ago.
I have a problem with my code.
I have such an info trying to build:
g++ -L /usr/local/boost_1_55_0 -Wall -pedantic -Iinc -c -lboost_system -pthread -lboost_thread -o obj/glo.o src/glo.cpp
g++ -L /usr/local/boost_1_55_0 -Wall -pedantic -Iinc -c -lboost_system -pthread -lboost_thread -o obj/serial.o src/serial.cpp
g++ -I /usr/local/boost_1_55_0 -Wall -lboost_system -pthread -o dwa obj/glo.o obj/serial.o
obj/glo.o: In function `__static_initialization_and_destruction_0(int, int)':
glo.cpp:(.text+0x15a): undefined reference to `boost::system::generic_category()'
glo.cpp:(.text+0x166): undefined reference to `boost::system::generic_category()'
glo.cpp:(.text+0x172): undefined reference to `boost::system::system_category()'
obj/glo.o: In function `boost::system::error_code::error_code()':
glo.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
and similar.
As You can see I have given
-lboost_system -pthread -lboost_thread and compiled system boost in /usr/local/boost_1_55_0
I have no idea whats happening.
Absolutely, g++ cannot find library boost_system. It should locate in /usr/local/boost_1_55_0/lib. You can add option "-v" to check the detailed error messages.
g++ -v -L/usr/local/boost_1_55_0/lib -Wall -lboost_system -pthread -o dwa obj/glo.o obj/serial.o
The commands should be as following:
g++ -I/usr/local/boost_1_55_0/include -Wall -pedantic -Iinc -c -o obj/glo.o src/glo.cpp
g++ -I/usr/local/boost_1_55_0/include -Wall -pedantic -Iinc -c -o obj/serial.o src/serial.cpp
g++ -L/usr/local/boost_1_55_0/lib -Wall -lboost_system -pthread -o dwa obj/glo.o obj/serial.o