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.
Related
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
When attempting to build the wxWidgets 3.1.0 library with the following command line:
mingw32-make -f makefile.gcc BUILD=release SHARED=1 CFLAGS="-O2 -flto"
CXXFLAGS="-O2 -flto" LDFLAGS="-O2 -flto"
I'm getting this warning (31 occurrences)
lto1.exe: warning: -fPIC ignored for target (all code is position independent)
Followed by:
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x13c4): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x1418): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x3792): undefined reference to `wx_regerror'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x37c1): undefined reference to `wx_regerror'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x3a7d): undefined reference to `wx_re_exec'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x47de): undefined reference to `wx_re_comp'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x4cf4): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x4f94): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x57c): undefined reference to `deflateEnd'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x88d): undefined reference to `deflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x8ba): undefined reference to `deflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x947): undefined reference to `deflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x4830): undefined reference to `deflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x59f4): undefined reference to `deflateInit2_'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans14.ltrans.o:<artificial>:(.text+0x3354): undefined reference to `deflateReset'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans14.ltrans.o:<artificial>:(.text+0x38db): undefined reference to `inflateReset'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x21d): undefined reference to `inflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x24a): undefined reference to `inflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x266): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x27d): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x2d0): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x121c): undefined reference to `inflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x1924): undefined reference to `inflateEnd'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x20b7): undefined reference to `inflateInit2_'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x3694): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x5534): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x5813): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x773e): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x7c5b): undefined reference to `crc32'
collect2.exe: error: ld returned 1 exit status
makefile.gcc:5299: recipe for target '..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll' failed
mingw32-make: *** [..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll] Error 1
Last lines emmited by the compiler and linker, which results in all these errors, are as follows:
g++ -c -o gcc_mswudll\basedll_main.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I..\..\lib\gcc_dll\mswu -I..\..\include -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswudll\basedll_main.o -MFgcc_mswudll\basedll_main.o.d -MD -MP ../../src/msw/main.cpp
g++ -c -o gcc_mswudll\basedll_volume.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I..\..\lib\gcc_dll\mswu -I..\..\include -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswudll\basedll_volume.o -MFgcc_mswudll\basedll_volume.o.d -MD -MP ../../src/msw/volume.cpp
g++ -shared -fPIC -o ..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll gcc_mswudll\basedll_dummy.o gcc_mswudll\basedll_version_rc.o gcc_mswudll\basedll_any.o gcc_mswudll\basedll_appbase.o gcc_mswudll\basedll_arcall.o gcc_mswudll\basedll_arcfind.o gcc_mswudll\basedll_archive.o gcc_mswudll\basedll_arrstr.o gcc_mswudll\basedll_base64.o gcc_mswudll\basedll_clntdata.o gcc_mswudll\basedll_cmdline.o gcc_mswudll\basedll_config.o gcc_mswudll\basedll_convauto.o gcc_mswudll\basedll_datetime.o gcc_mswudll\basedll_datetimefmt.o gcc_mswudll\basedll_datstrm.o gcc_mswudll\basedll_dircmn.o gcc_mswudll\basedll_dynarray.o gcc_mswudll\basedll_dynlib.o gcc_mswudll\basedll_dynload.o gcc_mswudll\basedll_encconv.o gcc_mswudll\basedll_evtloopcmn.o gcc_mswudll\basedll_extended.o gcc_mswudll\basedll_ffile.o gcc_mswudll\basedll_file.o gcc_mswudll\basedll_fileback.o gcc_mswudll\basedll_fileconf.o gcc_mswudll\basedll_filefn.o gcc_mswudll\basedll_filename.o gcc_mswudll\basedll_filesys.o gcc_mswudll\basedll_filtall.o gcc_mswudll\basedll_filtfind.o gcc_mswudll\basedll_fmapbase.o gcc_mswudll\basedll_fs_arc.o gcc_mswudll\basedll_fs_filter.o gcc_mswudll\basedll_hash.o gcc_mswudll\basedll_hashmap.o gcc_mswudll\basedll_init.o gcc_mswudll\basedll_intl.o gcc_mswudll\basedll_ipcbase.o gcc_mswudll\basedll_languageinfo.o gcc_mswudll\basedll_list.o gcc_mswudll\basedll_log.o gcc_mswudll\basedll_longlong.o gcc_mswudll\basedll_memory.o gcc_mswudll\basedll_mimecmn.o gcc_mswudll\basedll_module.o gcc_mswudll\basedll_mstream.o gcc_mswudll\basedll_numformatter.o gcc_mswudll\basedll_object.o gcc_mswudll\basedll_platinfo.o gcc_mswudll\basedll_powercmn.o gcc_mswudll\basedll_process.o gcc_mswudll\basedll_regex.o gcc_mswudll\basedll_stdpbase.o gcc_mswudll\basedll_sstream.o gcc_mswudll\basedll_stdstream.o gcc_mswudll\basedll_stopwatch.o gcc_mswudll\basedll_strconv.o gcc_mswudll\basedll_stream.o gcc_mswudll\basedll_string.o gcc_mswudll\basedll_stringimpl.o gcc_mswudll\basedll_stringops.o gcc_mswudll\basedll_strvararg.o gcc_mswudll\basedll_sysopt.o gcc_mswudll\basedll_tarstrm.o gcc_mswudll\basedll_textbuf.o gcc_mswudll\basedll_textfile.o gcc_mswudll\basedll_threadinfo.o gcc_mswudll\basedll_time.o gcc_mswudll\basedll_timercmn.o gcc_mswudll\basedll_timerimpl.o gcc_mswudll\basedll_tokenzr.o gcc_mswudll\basedll_translation.o gcc_mswudll\basedll_txtstrm.o gcc_mswudll\basedll_unichar.o gcc_mswudll\basedll_uri.o gcc_mswudll\basedll_ustring.o gcc_mswudll\basedll_variant.o gcc_mswudll\basedll_wfstream.o gcc_mswudll\basedll_wxcrt.o gcc_mswudll\basedll_wxprintf.o gcc_mswudll\basedll_xlocale.o gcc_mswudll\basedll_xti.o gcc_mswudll\basedll_xtistrm.o gcc_mswudll\basedll_zipstrm.o gcc_mswudll\basedll_zstream.o gcc_mswudll\basedll_fswatchercmn.o gcc_mswudll\basedll_fswatcherg.o gcc_mswudll\basedll_basemsw.o gcc_mswudll\basedll_crashrpt.o gcc_mswudll\basedll_debughlp.o gcc_mswudll\basedll_dde.o gcc_mswudll\basedll_dir.o gcc_mswudll\basedll_dlmsw.o gcc_mswudll\basedll_evtloopconsole.o gcc_mswudll\basedll_mimetype.o gcc_mswudll\basedll_power.o gcc_mswudll\basedll_regconf.o gcc_mswudll\basedll_registry.o gcc_mswudll\basedll_snglinst.o gcc_mswudll\basedll_stackwalk.o gcc_mswudll\basedll_stdpaths.o gcc_mswudll\basedll_thread.o gcc_mswudll\basedll_timer.o gcc_mswudll\basedll_utils.o gcc_mswudll\basedll_utilsexc.o gcc_mswudll\basedll_fswatcher.o gcc_mswudll\basedll_event.o gcc_mswudll\basedll_fs_mem.o gcc_mswudll\basedll_msgout.o gcc_mswudll\basedll_utilscmn.o gcc_mswudll\basedll_main.o gcc_mswudll\basedll_volume.o -mthreads -L..\..\lib\gcc_dll -Wl,--out-implib=..\..\lib\gcc_dll\libwxbase31u.a -O2 -flto -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet
What I've tried so far:
Added -fPIC to CFLAGS and CXXFLAGS, to no avail.
Use -fwhopr instead of -flto, as suggested by the MinGW-w64 Wiki but it's not recognized by either gcc.exe and g++.exe. After reading this article: Linktime optimization in GCC, part 1 - brief history, I'm assuming the -fwhopr option doesn't exist anymore and is now the default mode for the -flto switch.
Build the static configuration (SHARED=0). It builds successfully, but is unusable. See Reference #1.
Omit -flto from LDFLAGS - i.e. use -flto in CFLAGS and CXXFLAGS only. Also no avail.
How to get past these errors, and build wxWidgets with GCC's Link Time Optimization?
I'm building with MinGW-w64; threading model Win32; exception handling DWARF; GCC version 5.3.0.
Reference #1: Result from the "Minimal Sample" build command line
H:\temp\wxwidgets-3.1.0\samples\minimal>mingw32-make -f makefile.gcc BUILD=release SHARED=0 CFLAGS="-O2 -flto" CXXFLAGS="-O2 -flto" LDFLAGS="-O2 -flto"
windres --use-temp-file -i../../samples/sample.rc -ogcc_mswu\minimal_sample_rc.o --define __WXMSW__ --define NDEBUG --define _UNICODE --include-dir .\..\..\lib\gcc_lib\mswu --include-dir ./../../include --include-dir . --include-dir ./../../samples --define NOPCH
g++ -c -o gcc_mswu\minimal_minimal.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I.\..\..\lib\gcc_lib\mswu -I.\..\..\include -W -Wall -I. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswu\minimal_minimal.o -MFgcc_mswu\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswu\minimal.exe gcc_mswu\minimal_sample_rc.o gcc_mswu\minimal_minimal.o -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows -O2 -flto -lwxmsw31u_core -lwxbase31u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x191): undefined reference to `wxDefaultPosition'
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x197): undefined reference to `wxDefaultPosition'
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x1a8): undefined reference to `wxDefaultSize'
(Many, many other "undefined reference" errors - probably one for every function the code ever depends on) and then...
collect2.exe: error: ld returned 1 exit status
makefile.gcc:221: recipe for target 'gcc_mswu\minimal.exe' failed
mingw32-make: *** [gcc_mswu\minimal.exe] Error 1
I've never tried using LTO with DLLs before, but there are apparently bugs with doing it, see e.g. this one. Not sure if using the workaround proposed there can help in your case.
What I think should definitely work would be compiling your application sources and wxWidgets together at once, this would be similar to building a static library but shouldn't optimize away things unused in the library -- but used in the application code.
Finally, I'm really not sure if you're going to achieve much with LTO in wxWidgets case. There is not that much "slow" code to optimize in the library...
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
I have been scratching my head since yesterday trying to make gtest work but I just can't fix it after reading the links below.
undefined reference to `pthread_key_create' (linker error)
error during making GTest
The compilation error displayed is this:
g++ main.o tests.o var.o -L ../gmock/lib/.libs -L ../gmock/gtest/lib/.libs
-lgtest -lgmock -lpthread -o test
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_key_create'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_getspecific'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_key_delete'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
My Makefile is:
CXXFLAGS=-I ../gmock/include -I ../gmock/gtest/include
test:main.o tests.o var.o
g++ $^ -L ../gmock/lib/.libs -L ../gmock/gtest/lib/.libs -lgtest -lgmock -lpthread -o $#
I am still in the process of learning Linux, compiling and linking source files.
The Error is about linking error on pthread.
You have to make the pthread flag to -pthread and the follow CXX should do the trick.
LDLIBS = -L../gmock/lib/.libs -L../gmock/gtest/lib/.libs -lgtest -lgmock
test:main.o tests.o var.o
g++ -isystem $(LDLIBS) -pthread $^ -o $#
This link have a good Makefile which addresses all your problems and it follows general standards on creating a Makefile
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.