Undefined Reference to 'SNMP_Decode_Packet - c++

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.

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.

G++ ARM cross compiling: undefined references

I am trying to compile the Jasmine OpenSSD code with arm-none-eabi-g++.
However, it first failed with the following error message
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/bin/ld: cannot find -lstdc++
To fix that, I ensured that linking with libstdc++.a was possible. Once I fixed that, it failed with the following errors:
/usr/lib/gcc/arm-none-eabi/4.8.2//libgcc.a(unwind-arm.o): In function `get_eit_entry':
/build/buildd/gcc-arm-none-eabi-6/build/arm-none-eabi/libgcc/../../../gcc-4.8.2/libgcc/unwind-arm-common.inc:221: undefined reference to `__exidx_end'
/build/buildd/gcc-arm-none-eabi-6/build/arm-none-eabi/libgcc/../../../gcc-4.8.2/libgcc/unwind-arm-common.inc:221: undefined reference to `__exidx_start'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-abort.o): In function `abort':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
make: *** [firmware.elf] Error 1
Here is the actual step at which it fails:
arm-none-eabi-g++ -static -nostartfiles -ffreestanding -T ld_script -Wl,-O1,-Map=list.txt ftl.o sata_identify.o sata_cmd.o sata_isr.o sata_main.o sata_table.o initialize.o mem_util.o flash.o flash_wrapper.o misc.o uart.o init.o -o firmware.elf -L"/usr/lib/gcc/arm-none-eabi/4.8.2/" -lgcc
Can someone suggest a fix? Also, this works perfectly well if I use arm-none-eabi-gcc instead of arm-none-eabi-g++
Your problem is caused by exception handling code that is produced by the compiler, which relies on runtime components - those are not present in your build.
-fno-exceptions turns off exception handling in the code-generation of the compiler.

Qt: compilation issue with minGW

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!

g++ undefined reference though all files included

I have the problem that as the g++ tries to link the object files I receive the following error:
11:29:13 **** Build of configuration Debug for project daytime ****
make all
'Building target: daytime'
'Invoking: Cross G++ Linker'
g++ -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o
./tcf/services/daytime.o: In function `command_get_time_of_day':
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:38: undefined reference to `json_read_string'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:40: undefined reference to `exception'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:43: undefined reference to `exception'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:52: undefined reference to `write_stringz'
makefile:46: recipe for target 'daytime' failed
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:54: undefined reference to `write_stringz'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:56: undefined reference to `write_errno'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:58: undefined reference to `json_write_string'
./tcf/services/daytime.o: In function `ini_daytime_service':
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:70: undefined reference to `add_command_handler'
collect2.exe: error: ld returned 1 exit status
make: *** [daytime] Error 1
I have no idea why this is the case since e.g. #include <tcf/framework/json.h>is included and found.
Didn't gcc compile the corresponding *.c files such that this linker error occurs?
What is the problem here?
Thank you.
It is not enough to include the header files; you also have to specify the libraries where those functions are defined.
To make the linker find all those methods/classes (json_read_string, write_stringz, exception) you need to reference the library. If e.g. they are contained in a library called libjson.so, you should do:
g++ -ljson -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o
(or add the library to the project options, if eclipse is managing your make files).
Or if it's another .o file, include that in the compilation (-> or in the project, if eclipse is creating the make file).