Qt: compilation issue with minGW - c++

I got a Qt environment that I need to compile.
But when compiling, I get the following messages:
g++ -Wl,-s -mthreads -Wl,-subsystem,windows -o release\Prog.exe object_script.Prog.Release -L"c:\DevProgs\Qt\4.8.6\lib" -lmingw32 -lqtmain build\objects\myapp_res.o -LC:/Windows/System32 -lftd2xx -LC:/qwt-6.0.1/lib -lqwt -lQtSql4 -lQtGui4 -lQtNetwork4 -lQtCore4
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x1fb): undefined reference to `_imp__Sleep#4'
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x293): undefined reference to `_imp__SetUnhandledExceptionFilter#4'
Makefile.Release:303: recipe for target 'release\Prog.exe' failed
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x2a7): undefined reference to `_set_invalid_parameter_handler'
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x475): undefined reference to `_imp__GetStartupInfoA#4'
[MGWPATH]/i686-w64-mingw32/bin/ld.exe: [MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o: bad reloc address 0x0 in section `.CRT$XCAA'
collect2.exe: error: ld returned 1 exit status
where [MGWPATH] is C:/DevProgs/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../..
I sucessfully ran small demos of Qt4.8.6 alone and one with Qwt.
The only doubt I have is regarding the ftd2xx lib.
But, I think it is linked properly because I am able to produce errors of undefined function if I don't link the DLL.
The error message is not clear to me. So, I have absolutely no idea where to look from here!
Could someone help me?
Thank you!

Related

undefined reference to FOLDERID_.. - C++

compiling c++ from linux to windows using g++ and got an error.
Error:
undefined reference to `FOLDERID_RoamingTiles'
collect2: error: ld returned 1 exit status
I'm guessing there is a library I have to reference but I don't know what the name is.
also if that's the case what are the ways I could find the name of the library I have to reference, if that happens again in the future?
thanks.
I'm compiling under msys2/gcc. linking to uuid helped me.
g++ -luuid -o ....

Undefined Reference to `SDL2_Init` with LD when G++ is not giving an error

(FYI Yes I do know that a similar question exists, But I have already tried all the answers.)
I'm trying to setup SDL2 with MinGW and I have everything set up beside one thing. Whenever I try to compile G++ gives no errors but then LD gives me a: undefined reference to SDL_Init Error.
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc28dE2R.o: in function `SDL_main':
C:\Users\user\Documents\SDL2/src/main.cpp:11: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:14: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:18: undefined reference to `IMG_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:20: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lmingw32 -lSDL2main -lSDL2_image -lSDL2" terminated with exit code: 1.
I have tried to move the args around. doing -mwindows, adding -lmingw32. I still keep getting the same errors.. I was able to fix the WinMain Error.. But everything else I couldn't fix.
The command I'm Running to compile:
C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lSDL2main -lSDL2_image -lSDL2
If i could get any help that would be amazing
The common cause of mysterious undefined reference errors on MinGW is using libraries compiled for x64 with an x32 compiler, or vice versa. SDL ships both x32 and x64 ones, try the other ones.
I was able to fix the WinMain Error
Be aware that the intended way of fixing undefined reference to WinMain#16 is not adding #define SDL_MAIN_HANDLED and not doing #undef main. Once you get the right libraries (see the first paragraph), the error should disappear by itself.
Make sure you use int main(int, char**) (and not int main() nor void main()), otherwise it won't work.
-ID:C:\MinGW\include -LD:C:\MinGW\lib
You shouldn't need those flags. Those directories will be searched automatically.
Since you didn't specify any other directories, I assume you placed the SDL files directly into the compiler directories, which isn't a good practice, IMO.
I assume D:C: a typo?
-mwindows
The only purpose of this flag (that I know of) is to prevent your app from automatically opening a terminal window for itself, for release builds.

Undefined Reference to 'SNMP_Decode_Packet

I am using CodeBlocks to compile a project I have inherited from an ex-colleague. One part of the project compiles correctly (it is split using build target files), the other part compiles with the following errors:
pinger.c: undefined reference to 'SNMP_Decode_Packet'
pinger.c: undefined reference to 'SNMP_Free'
The build log is as below:
[100.0%] mingw32-g++.exe -L..\pcap\Lib -o bin\Release\ZTC.exe obj\Debug_common\custom.o obj\Debug_common\dialog_common.o obj\Debug_common\setinifilename.o obj\Debug_gui\about.o obj\Debug_gui\browse.o obj\Debug_gui\gui_bootpd.o obj\Debug_gui\gui_bootpd_settings.o obj\Debug_gui\gui_conf_decode.o obj\Debug_gui\gui_conf_items.o obj\Debug_gui\gui_conf_top.o obj\Debug_gui\gui_dialog.o obj\Debug_gui\gui_gauges.o obj\Debug_gui\gui_log.o obj\Debug_gui\gui_main.o obj\Debug_gui\gui_move_win.o obj\Debug_gui\gui_pinger.o obj\Debug_gui\gui_pinger_settings.o obj\Debug_gui\gui_settings.o obj\Debug_gui\gui_tftp_dir.o obj\Debug_gui\gui_tftpd.o obj\Debug_gui\gui_ztp.o obj\Debug_gui\gui_ztp_settings.o obj\Debug_gui\tftp_cli.o obj\Debug_libs\conf\conf.o obj\Debug_libs\dump\dump.o obj\Debug_libs\event_log\eventlog.o obj\Debug_libs\GUI\Cmsgbox.o obj\Debug_libs\GUI\listview.o obj\Debug_libs\GUI\window.o obj\Debug_libs\lasterr\lasterr.o obj\Debug_libs\libtelnet\libtelnet.o obj\Debug_libs\linked_list\linked_list.o obj\Debug_libs\log\LogToMonitor.o obj\Debug_libs\md5\md5.o obj\Debug_libs\memdebug\cMemDbg.o obj\Debug_libs\mini_tcp4u\mini_tcp4u.o obj\Debug_libs\mini_tcp4u\tcp4u_exchg.o obj\Debug_libs\mini_tcp4u\udp4u.o obj\Debug_libs\ping_api\ping_api.o obj\Debug_libs\registry\registry.o obj\Debug_libs\scandir\scandir.o obj\Debug_libs\snmp\BUFFER.o obj\Debug_libs\snmp\DECODE.o obj\Debug_libs\snmp\ENCODE.o obj\Debug_libs\snmp\LIBFUNCS.o obj\Debug_libs\snmp\LOCALIO.o obj\Debug_libs\snmp\OBJECTID.o obj\Debug_libs\snmp\snmp_d.o obj\Debug_libs\snmp\SNMP_E.o obj\Debug_libs\snmp\sprint.o obj\Debug_libs\ztc_database\ztc_database.o obj\Debug_libs\ztp_api\ztp.o obj\Debug_libs\ztp_api\ztp_raw.o obj\Debug_main\cmd_line.o obj\Debug_main\main.o obj\Debug_main\outofthebox.o obj\Debug_services\async_log.o obj\Debug_services\bootpd.o obj\Debug_services\bootpd_console.o obj\Debug_services\bootpd_util.o obj\Debug_services\console_actions.o obj\Debug_services\ip_thread.o obj\Debug_services\ip_util.o obj\Debug_services\pinger.o obj\Debug_services\registry_thread.o obj\Debug_services\service_main.o obj\Debug_services\settings.o obj\Debug_services\start_threads.o obj\Debug_services\tftp_dbg.o obj\Debug_services\tftpd_main.o obj\Debug_services\tftpd_thread.o obj\Debug_services\tftpd_util.o obj\Debug_services\to_console.o obj\Debug_services\ztp.o obj\Debug_services\ztp_util.o obj\Debug\telnet.o obj\Debug_res\resource.res -lGdi32 -lcomdlg32 -lcomctl32 -lwpcap -lws2_32 -liphlpapi -Wl,--subsystem,windows -mwindows
obj\Debug_services\pinger.o:pinger.c:(.text+0x2ca): undefined reference to SNMP_Decode_Packet'
obj\Debug\_services\pinger.o:pinger.c:(.text+0xc98): undefined reference toSNMP_Free'
collect2.exe: error: ld returned 1 exit status
I have tried moving the pinger.o file before and after snmp.o file which contains the SNMP_Decode_Packet and SNMP_Free functions to no avail, the above log is the default positioning.
I can provide more information if it helps.
It is probably a simple error but any help to solve the issue would be greatly appreciated.

Checking Boost install with MinGW

I used the MinGW installation at http://nuwen.net/mingw.html
I ran the second.cpp test found at:
http://tabreziqbal.wordpress.com/2006/03/16/how-to-test-c-boost-installation/
(I used the correct commands to run from the comments, which was
g++ -o second second.cpp -lboost_filesystem)
I get the following error:
C:\Users\user\Projects\Programming\C++\boostTest2>g++ -o second second.cpp -lboost_filesystem
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x102): undefined reference to boost::system::generic_cat
egory()'
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x10c): undefined reference toboost::system::generic_cat
egory()'
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x116): undefined reference to boost::system::system_cate
gory()'
C:\MinGW\bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccDlbKGy.o: bad reloc address 0xe in section.text$_ZN5boost6syst
em14error_categoryD1Ev[__ZN5boost6system14error_categoryD1Ev]'
C:\MinGW\bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
I know there's an installation test feature of boost that I found on
http://gcc.gnu.org/testing/testing-boost.html
but those files aren't included with the distribution from nuwen.net (so I'd have to do it myself).
And help is appreciated - I figure I'm just screwing up something minor (I hope anyway).
Thanks all!
It's not correct command, you should link boost::system too (errors are undefined references to boost::system::system_category).
Correct command will be g++ -o second second.cpp -lboost_system -lboost_filesystem

with -lpthread, g++ compiler error, "undefined reference to " semaphore calls such as `sem_open'

I am new to posix thread library, and I tried to compile a sample code from a tutorial with:
g++ -lpthread agreement.cpp -o agreement
however I was not able to compile the code and got the following error message:
a3q2.cpp:(.text+0x7e): undefined reference to `sem_open'
a3q2.cpp:(.text+0xab): undefined reference to `sem_wait'
a3q2.cpp:(.text+0x290): undefined reference to `sem_post'
a3q2.cpp:(.text+0x2af): undefined reference to `sem_close'
a3q2.cpp:(.text+0x2bb): undefined reference to `sem_unlink'
collect2: ld returned 1 exit status
make: *** [a3q2_exe] Error 1
I am aware that -lpthread is needed for compilation to work, but is there any other options i might need to solve the problem? if not how do I have to install the "proper" pthread library?
Thanks for your help!
You want the compile option -pthread (if you are really using pthreads). If you just need those functions they are in librt so use -lrt