undefined reference c++ mingw32 [duplicate] - c++

This question already has answers here:
g++ linking order dependency when linking c code to c++ code
(4 answers)
Closed 6 years ago.
I made a TCP socket program in C++ that uses wsock32 and openssl, but I want to link openssl static.
I have compiled openssl on mingw32 with shared and no-shared but I keep getting the same undefined reference errors.
It builds fine if I link the .a.dll instead of .a but I don't want to use dll's.
Here's how I compile:
/c/MinGW/bin/mingw32-g++.exe main.cpp -I /c/Mingw-builds/openssl/include -L/c/MinGW/lib -L /c/Mingw-builds/openssl/lib -std=c++11 -lwsock32 -lshlwapi -lws2_32 -lssl -lcrypto -lgdi32
Errors that I get:
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xac): undefined reference to `getnameinfo#28'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0x6ef): undefined reference to `freeaddrinfo#4'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xa28): undefined reference to `getaddrinfo#16'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0xe6): undefined reference to `WSAGetLastError#0'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x2d6): undefined reference to `WSAGetLastError#0'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x40b): undefined reference to `getsockopt#20'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x43b): undefined reference to `gethostbyname#4'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x4a0): undefined reference to `WSAGetLastError#0'

Nvm got it working by ordering it right:
/c/MinGW/bin/mingw32-g++.exe main.cpp -o asdf.o -I /c/Mingw-builds/openssl/include -L /c/Mingw-builds/openssl/lib -std=c++11 -lmingw32 -lssl -lcrypto -luser32 -lgdi32 -lws2_32 -lwsock32 -lshlwapi -static-libgcc -static-libstdc++ -shared

Related

vscode won't let me execute raylib

gcc core_basic_window.c -o game.exe -o1 -Wall -std=c99 -Wno-missing-braces -I include/ -L Iraylib -Iopeng132 -Igdi32 -Iwinmm
D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x37): undefined reference to InitWindow' D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x43): undefined reference to SetTargetFPS'
D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x4a): undefined reference to BeginDrawing' D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x72): undefined reference to ClearBackground'
JZC.o:core_basic_window.c:(.text+0xc4): undefined reference to EndDrawing' D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0xc9): undefined reference to WindowShouldClose'
D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0xd9): undefined reference to `CloseWindow'
collect2.exe: error: ld returned 1 exit status
it won't work...
I am using vscode and putted all task.
vscode will say that it isn't defined.
Your command:
gcc core_basic_window.c -o game.exe -o1 -Wall -std=c99 -Wno-missing-braces -I include/ -L Iraylib -Iopeng132 -Igdi32 -Iwinmm
Contains a lot of typos, and contains -Is where -ls are required. The following compiles for me:
g++ main.cpp -I"Path_to_Raylib" -L"Path_to_Raylib" -lraylib -lopengl32 -lgdi32 -lwinmm
Given my system's file structure, I would write the following:
g++ main.cpp -I"C:\raylib\raylib-4.0.0_win64_mingw-w64\include" -L"C:\raylib\raylib-4.0.0_win64_mingw-w64\lib" -lraylib -lopengl32 -lgdi32 -lwinmm
If you want to use C, you would obviously change g++ to gcc and you would add things like -o if you want a specific name for your output file.
I hope this was helpful.

How to link a SQLite c file (the Amalgamation) with cpp application? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I want to build this process on an embedded Linux without installing sqlite3 or sqlite3-dev (I already tried to install them and it worked out).
I've 4 files in the directory : main.cpp sqlite3.c sqlite3.h example.db
I included the sqlite3.h in the main.cpp this way:
extern "C"{
#include "sqlite3.h"
}
Then I typed those commands :
gcc -c sqlite3.c -o sqlite3.o
g++ -c main.cpp -o main.o
and it was already so far, then I wrote this
g++ -o main.out main.o -L.
but I'm getting those errors
main.o: In function `main':
main.cpp:(.text+0xf6): undefined reference to `sqlite3_open'
main.cpp:(.text+0x16d): undefined reference to `sqlite3_exec'
main.cpp:(.text+0x1c6): undefined reference to `sqlite3_exec'
main.cpp:(.text+0x1f7): undefined reference to `sqlite3_free'
main.cpp:(.text+0x25c): undefined reference to `sqlite3_exec'
main.cpp:(.text+0x299): undefined reference to `sqlite3_exec'
main.cpp:(.text+0x2ca): undefined reference to `sqlite3_free'
main.cpp:(.text+0x32f): undefined reference to `sqlite3_exec'
main.cpp:(.text+0x33b): undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status
How to statically link those files?
You're not actually linking with the SQLite object file sqlite3.o.
The linker doesn't know about files or libraries that aren't specified explicitly, so you need to do e.g.
g++ -o main.out main.o sqlite3.o
Considering the other error you get, you need to build with the -pthread option, both when compiling and when linking.
And the -L option is to add a path that the library searches for libraries you name with the -l (lower-case L) option. The linker will not automatically search for any libraries or object files. You really need to specify them explicitly when linking.
To summarize, build like this:
g++ -Wall -pthread main.cpp -c
gcc -Wall -pthread sqlite3.c -c
g++ -pthread -o main.out main.o sqlite3.o -ldl
Note that we now also link with the dl library, as specified in the documentation linked to by Shawn.

Undefined reference to glew [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
while I am working on rendering fonts using ftgl in my opengl project I am encountering errors stating
g++ -o mygame Sample_GL3_2D.cpp glad.c -lGL -lglfw -ldl -lftgl -lSOIL -I /usr/include/freetype2 -L/usr/local/lib -lfreetype
/usr/local/lib/libftgl.so: undefined reference to `__glewGenBuffers'
/usr/local/lib/libftgl.so: undefined reference to `glewInit'
/usr/local/lib/libftgl.so: undefined reference to `__glewBindVertexArray'
/usr/local/lib/libftgl.so: undefined reference to `__glewBindBuffer'
/usr/local/lib/libftgl.so: undefined reference to `__glewUniform3f'
/usr/local/lib/libftgl.so: undefined reference to `__glewVertexAttribPointer'
/usr/local/lib/libftgl.so: undefined reference to `__glewBufferData'
/usr/local/lib/libftgl.so: undefined reference to `__glewDeleteBuffers'
/usr/local/lib/libftgl.so: undefined reference to `__glewDeleteVertexArrays'
/usr/local/lib/libftgl.so: undefined reference to `__glewGenVertexArrays'
/usr/local/lib/libftgl.so: undefined reference to `__glewEnableVertexAttribArray'
these are my contents in Makefile
all:mygame
mygame: Sample_GL3_2D.cpp glad.c
g++ -o mygame Sample_GL3_2D.cpp glad.c -lGL -lglfw -ldl -lftgl -lSOIL -I /usr/include/freetype2 -L/usr/local/lib -lfreetype
clean:
rm mygame
looks like the errors is being raised by the libftgl.so library. I have installed the GLEW using the glew packages in the ubuntu. but dont understand why it isn't being referenced.
You aren't referencing the GLEW library on the compile/link line. The -l flag to g++ is tells it to tell the linker to the link the library e.g. -lftgl tells it to look for the ftgllibrary and link it.
You don't have -lGLEW (or -lglew if the library is named using lowercase) so it isn't linked. Also see this answer
error undefined reference to `FTExtrudeFont::FTExtrudeFont(char const*)'
Maybe the two of you should get together and try and help each other since you are appear to be trying to solve the same (homework?) problem.

cUrl: Undefined reference

I am trying to use cUrl in my app but i am getting several errors. I already tried to find a solution on g or here, but nothing helped.
I build and link cUrl as static, have libcurl.a set up in linker, have proper includes but it still doesn't work.
I tried adding -lcurl into build settings but seems like it doesn't know that flag.
I am using cUrl 7.46.0 build with --disable--static and --without--ssl
and Code::Blocks ide & mingw compiler // c++ ofc
Here are those errors:
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_cleanup'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_cleanup'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_init'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_setopt'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_perform'
Compilation command:
mingw32-g++.exe -LC:\WXWID\lib\gcc_lib -o bin\Release\app.exe obj\Release\app.o obj\Release\appMain.o obj\Release\appHistory.o obj\Release\src\HTTPDownloadRequest.o obj\Release\resource.res -s -static-libgcc -static-libstdc++ -static -mthreads -lwxmsw30u_core -lwxbase30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib C:\WXWID\lib\gcc_lib\libwxmsw30u_adv.a "C:\curl\lib\libcurl.a" -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
Errors when used define CURL_STATICLIB
C:\curl\lib\libcurl.a(libcurl_la-connect.o)| undefined reference to `WSAIoctl#36'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)| undefined reference to `_imp__ldap_err2stringA'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)| undefined reference to `_imp__ldap_msgfree'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)|| undefined reference to `_imp__ldap_unbind_s'
...
If you try to link with static libcurl add -DCURL_STATICLIB to gcc arguments or define CURL_STATICLIB macro before including its headers to use correct mangling.
I would do
mingw32-g++.exe -LC:\curl\lib -lcurl ................

Linking libcurl while cross compiling with mingw32 under Linux for Windows

I have compiled libcurl using mingw32 and am trying to link it with my program using mingw32 for a Windows system from my Linux machine.
I was outputted the files, libcurl-4.dll libcurl.a libcurl.la libcurl.lai.
I have included them in my mingw32 libs folder at: /usr/x86_64-w64-mingw32/lib
I was able to find a few other topics on linking with the libstdc++ and libgcc to take care dependency errors while executed but when trying to add libcurl.a it will not compile period.
I used the following:
$ x86_64-w64-mingw32-g++ main.cpp -o hello.exe -static-libgcc -static-libstdc++ -static "/usr/x86_64-w64-mingw32/lib/libcurl.a" -lpthread
However, I cannot not get it to use the libcurl.a and am continuing to receive these errors.
/tmp/ccIceRus.o:main.cpp:(.text+0xde): undefined reference to `__imp_curl_easy_init'
/tmp/ccIceRus.o:main.cpp:(.text+0x106): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x122): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x13e): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x159): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x169): undefined reference to `__imp_curl_easy_perform'
/tmp/ccIceRus.o:main.cpp:(.text+0x180): undefined reference to `__imp_curl_easy_strerror'
/tmp/ccIceRus.o:main.cpp:(.text+0x197): undefined reference to `__imp_curl_easy_cleanup'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccIceRus.o: bad reloc address 0x80 in section `.xdata'
collect2: error: ld returned 1 exit status
What am I doing wrong?. I can not get past this. I know it has to be some stupid issue.
Thank you.
I was able to solve the question by specifying -DCURL_STATICLIB, as well as linking some other dependencies.
x86_64-w64-mingw32-g++ main.cpp -o hello.exe -DCURL_STATICLIB -static -lstdc++ -lgcc -lpthread -lcurl -lwldap32 -lws2_32