0
Hello, I’m a beginner in C++. My mission is to successfully include the Curl library, from static form without DLL (code must be included in . exe). After a lot of research, trial and frustration compiling in Visual Studio 2019, I decided to use the c++ compiler for windows, on linux, doing the process manually to try to understand the error that repeats.
Code I try to compile (main.cpp file):
#include "curl/curl.h"
int main(){
// Inicia o cURL
CURL* curl;
curl = curl_easy_init();
return 0;
}
Command I use to compile (on Linux):
i686-w64-mingw32-g++ -static-libgcc -static-libstdc++ -DCURL_STATICLIB -Ilibs/curl/include -Llibs/curl/lib -l libcurl_a main.cpp -o main.exe
Error while compiling:
/tmp/cc1qyBYq.o:main.cpp:(.text+0x36): undefined reference to `curl_easy_init'
Project file structure (convenience):
projeto/
-main.cpp
-libs/
-curl/
-include/curl/<todos os header files>
-lib/libcurl_a.lib
OBS: I have tried in several ways this compilation on Windows also.
How I compiled the Curl library (on a Windows machine):
- Downloaded from the official website (Curl);
- I used the Developer Command Prompt of the VS to make the
compilation.
nmake /f Makefile.vc mode=static
. - In the builds directory, the folder was generated
libcurl-vc-x86-release-static-ipv6-sspi-winssl
, where they are containedinclude/
andlib/
. - I transferred the files to the project directory (on the Linux machine), organized as I presented above.
I’ve done a lot of research on it, according to what I understand:
I have compiled the files from the Curl library;
I informed the compiler and the headers of Curl that I am using the static library (
-DCURL_STATICLIB
)- I imported the header file directory (
-Ilibs/curl/include
) - I imported the library directory (
-Llibs/curl/lib
) - I imported the library (
-l libcurl_a
)
It’s very frustrating, because I’ve made several attempts and I’m not successful. Please help, I believe it is a recurring error, too, for other beginners in the language. Thank you from now.
Running the command in verbose mode:
i686-w64-mingw32-g++ -static-libgcc -static-libstdc++ -DCURL_STATICLIB -Ilibs/curl/include -Llibs/curl/lib -l libcurl_a main.cpp -o main.exe -v
[Código anterior não mostrado por, aparentemente, não ter relevância]
GNU C++14 (GCC) version 7.3-win32 20180312 (i686-w64-mingw32)
compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d199463242a5239abcb58b29395ecf5b
COLLECT_GCC_OPTIONS='-static-libgcc' '-D' 'CURL_STATICLIB' '-I' 'libs/curl/include' '-Llibs/curl/lib' '-o' 'main.exe' '-v' '-mtune=generic' '-march=pentiumpro'
/usr/bin/i686-w64-mingw32-as -v -I libs/curl/include -o /tmp/cck4iQxU.o /tmp/ccWzC4RY.s
GNU assembler version 2.30 (i686-w64-mingw32) using BFD version (GNU Binutils) 2.30
COMPILER_PATH=/usr/lib/gcc/i686-w64-mingw32/7.3-win32/:/usr/lib/gcc/i686-w64-mingw32/7.3-win32/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/7.3-win32/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/7.3-win32/../../../../i686-w64-mingw32/bin/
LIBRARY_PATH=/usr/lib/gcc/i686-w64-mingw32/7.3-win32/:/usr/lib/gcc/i686-w64-mingw32/7.3-win32/../../../../i686-w64-mingw32/lib/../lib/:/usr/lib/gcc/i686-w64-mingw32/7.3-win32/../../../../i686-w64-mingw32/lib/
COLLECT_GCC_OPTIONS='-static-libgcc' '-D' 'CURL_STATICLIB' '-I' 'libs/curl/include' '-Llibs/curl/lib' '-o' 'main.exe' '-v' '-mtune=generic' '-march=pentiumpro'
/usr/lib/gcc/i686-w64-mingw32/7.3-win32/collect2 -m i386pe -Bdynamic -o main.exe /usr/lib/gcc/i686-w64-mingw32/7.3-win32/../../../../i686-w64-mingw32/lib/../lib/crt2.o /usr/lib/gcc/i686-w64-mingw32/7.3-win32/crtbegin.o -Llibs/curl/lib -L/usr/lib/gcc/i686-w64-mingw32/7.3-win32 -L/usr/lib/gcc/i686-w64-mingw32/7.3-win32/../../../../i686-w64-mingw32/lib/../lib -L/usr/lib/gcc/i686-w64-mingw32/7.3-win32/../../../../i686-w64-mingw32/lib -llibcurl_a /tmp/cck4iQxU.o -Bstatic -lstdc++ -Bdynamic -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt /usr/lib/gcc/i686-w64-mingw32/7.3-win32/crtend.o
/tmp/cck4iQxU.o:main.cpp:(.text+0xf): undefined reference to `curl_easy_init'
collect2: error: ld returned 1 exit status
It would be nice to try directly through the prompt and add the log in the post
– Bacco
@Bacco I don’t know is what you asked for.
– Pedro Henrique