Linker Error (LNK2019) undefined reference to __imp_ - c

I am working on open62541 open source project.I have built the project using Cmake as mentioned here at the following webpage open62541.org and generated the open62541.c ,open62541.h files in the project's build folder.Then I created a new folder called C_project inside the build folder and copied the generated files into this folder.
Now I am trying to build a minimal server(C_Project/myServer.c) by following the steps given at the following page open62541/sever.I am getting the following link errors.
C:\SPB_Data\open62541\build\C_Projects\OPC_UA>cmd /c gcc -std=c99 open62541.c myServer.c -lws2_32 -o myServer.exe > output.txt
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x98): undefined reference to `__imp_UA_ServerConfig_setMinimalCustomBuffer'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0xd8): undefined reference to `__imp_UA_Log_Stdout'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x132): undefined reference to `__imp_UA_Server_new'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x146): undefined reference to `__imp_UA_Server_getConfig'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x165): undefined reference to `__imp_UA_Server_run'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x178): undefined reference to `__imp_UA_Server_delete'
collect2.exe: error: ld returned 1 exit status
I used the following command to build the project:
$ gcc -std=c99 open62541.c myServer.c -o myServer
I tried to find the solutions for this by searching in the web. The only thing that I could get out of that is it might be a error due to dll files. Kindly help.

-open62541.lib specifies that the result of compilation should be written to file pen62541.lib.
And -o myServer.exe says that it should be written to myServer.exe instead.
And GCC will then ignore the first output file name.
Solution: remove the - from the library name.

I had similar problem as you when I made the CMake build with BUILD_SHARED_LIBS on.
For me it was working when I installed open62541 with CMake options UA_ENABLE_AMALGAMATION on and UA_NAMESPACE_ZERO full (rest default)
I compiled with the command
gcc -std=c99 myserver.c open62541.c -o server -lws2_32
Inside the selected folder are just the files open62541.c/.h and myserver.c

Related

libtiff build undefined reference to `_imp__TIFFOpen' error

probably this is a trivial newbie question, however, I can't figure out how to solve it.
I'm trying to build a test program using libtiff (test program copied from here). I've downloaded the static library libtiff.lib as well as the required header file tiffio.h. When I compile the main c function with no problem I have a main.o file. When I try to link main.o with libtiff using this command
gcc -g -Wall -o test.exe ./libtiff.lib ./test.o
I have this error:
undefined reference to `_imp__TIFFOpen'
I've looked into the lib file with nm -A libtiff.lib command and I can find this line
libtiff.lib:libtiff3.dll:00000000 I __imp__TIFFOpen
but it has 2 leading underscores instead of 1 as required by the linker. I'm using mingw on Windows 7 and all the required files are in the same directory.
No clue how to link with no errors.
Thanks in advance.
As suggested in the the comments, it was sufficient to invert the order of objects passed as arguments:
gcc -g -Wall -o test.exe ./test.o ./libtiff.lib

Undefined Reference to imp using mingw

The problem I have is the "undefined reference to '_imp__...' " error that comes up when I build my project. I am using Windows 7, MinGW, Eclipse and .lib and .dll file that I did not make, but I took directly from the company that sold me their product.
I link with the -l command the HRDL.lib file and i have the PicoHRDL.dll at the same directory. The lib file is found (I'm sure about this), but the error comes up. I have included the complete path with the -L command. I have included the header file with the declarations of the functions, I get the undefined reference to, but the error is still there.
I have contacted both Eclipse support and Picotech support (the said company) but they weren't able to locate the problem till now.
These are the commands:
gcc -O0 -g -Wall -c -fmessage-length=0 -o ACD_SOURCE.o "..\\ACD_SOURCE.c"
gcc "-LC:\\Users\\Falamana\\Desktop\\Eclipse\\ADC_project1\\Libraries" -shared -o libADC_24_DataLogger_App.exe ACD_SOURCE.o -lHRDL
These are the errors:
ACD_SOURCE.o: In function `main':
C:\Users\Falamana\Desktop\Eclipse\ADC_project1\Debug/../ACD_SOURCE.c:70:
undefined reference to `_imp__HRDLGetUnitInfo#16'
C:\Users\Falamana\Desktop\Eclipse\ADC_project1\Debug/../ACD_SOURCE.c:99:
undefined reference to `_imp__HRDLCloseUnit#4'
ACD_SOURCE.o: In function `SelectUnit':
C:\Users\Falamana\Desktop\Eclipse\ADC_project1\Debug/../ACD_SOURCE.c:115:
undefined reference to `_imp__HRDLGetUnitInfo#16'
C:\Users\Falamana\Desktop\Eclipse\ADC_project1\Debug/../ACD_SOURCE.c:167:
undefined reference to `_imp__HRDLGetUnitInfo#16'
In my case it helpt to add -mwindows flag to linker options.
Note that in your compiling information, the -L option symbol should be out of the quote. That's to say, the
gcc "-LC:\Users\Falamana\Desktop\Eclipse\ADC_project1\Libraries" -shared -o libADC_24_DataLogger_App.exe ACD_SOURCE.o -lHRDL
should be
gcc -L"C:\Users\Falamana\Desktop\Eclipse\ADC_project1\Libraries" -shared -o libADC_24_DataLogger_App.exe ACD_SOURCE.o -lHRDL
So please check your configuration of the lib directory in whatever IDE you are using, util the gcc line of compiling information looks normal( util -L stands right ahead of the quote character).

Can't link against WinPcap library wpcap.lib ("undefined reference to")

I am trying to build an example program which uses WinPcap-functions. I’m working under Windows 7 64 Bit edition with MinGW. I am able to compile the C-code to an object file, but I can’t link against wpcap.lib.
My linker call looks like this:
gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe
With this call I get the following errors:
undefined reference to pcap_open
undefined reference to pcap_sendpacket
undefined reference to pcap_geterr
Obviously I am not linking against wpcap.lib, but I don’t know why. The library is definitely found. If I change the lib include path for example, I get this error:
cannot find -lwpcap
Why does the linker find the lib but does not link against it? Thanks for your help.
Try listing you libraries after binary definition. As far as I remember, with provided gcc command, ld would be symbol matching for pcap symbols between send_packet.o and libwpcap.lib but not with WinPcapTest.exe. I would suggest moving -lwpcap at the end:
gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -O0 -g3 -Wall -o WinPcapTest.exe -lwpcap

Compiling a c application that links to a static library on AIX

I'm trying to compile my application to link to a static library (.a file)
The command I use to build is this:
gcc -DUNIX -maix32 -o Release/bin/testApp Release/obj/main.o -ltestLib
When I build I get the following errors:
ld: 0711-317 ERROR: Undefined symbol: .test
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
Where test is a method in libtestLib.a
Also if I try and build with a dynamic lib then it is successful.
gcc -DUNIX -maix32 -o Release/bin/testApp Release/obj/main.o libtestLib.so
Can you see where I am going wrong?
Can you try specifying a path to the archive file, rather than -ltestLib?
gcc -DUNIX -maix32 /path/to/testLib.a -o Release/bin/testApp Release/obj/main.o

Undefined reference to t1sl_steup_key_block when linking OpenSSL

I got a problem of linking an OpenSSL library into an existing project.
Where I do get it wrong?
Below are the steps I have followed.
I have downloaded the SSL library, configured and installed it. It gets installed in /usr/local/ssl.
2) I have copied libcrypto.a and libssl.a from /usr/local/ssl/lib into my project, something like /mnt/linux/bla/bla/lib.
3) Then I edit the make file and added path of libssl libcrpto there. The path added is one that is in project like /mnt/linux/bla /bla
3) make
4) build project via slick edit
When it builds I get a long error chain, like
../lib/libssl.a(t1_enc.o) :In function 't1sl_steup_key_block: undefined ref
Now, I guess copying .a files into project could be problem. Is there is any alternative for that or should I use ln -s to link .a files form /usr/local/openssl/lib into my project library folder? Below is the error.
Debug/FC5/m2pa.o -ldl -lpthread -ltdapi ../septel/gctlib.lib ../lib/libpq.a ../asn1/lib/libasn1per.a ../mysql/lib/libmysqlclient.a -L../lib ../asn1/lib/libasn1rt.a -lm -lcrypt -lcrypto -lssl -rdynamic
../lib/libssl.a(ssl_lib.o): In function `SSL_set_quiet_shutdown':ssl_lib.c:(.text+0x670): multiple definition of `SSL_set_quiet_shutdown'
../mysql/lib/libmysqlclient.a(ssl.o):ssl.cpp:(.text+0x125c): first defined here
/usr/bin/ld: Warning: size of symbol `SSL_set_quiet_shutdown' changed from 45 in ../mysql/lib/libmysqlclient.a(ssl.o) to 12 in ../lib/libssl.a(ssl_lib.o)
../lib/libssl.a(ssl_lib.o): In function `SSL_get_quiet_shutdown':ssl_lib.c:(.text+0x680): multiple definition of `SSL_get_quiet_shutdown'
../mysql/lib/libmysqlclient.a(ssl.o):ssl.cpp:(.text+0x12down' changed from 35 in ../mysql/lib/libmysqlclient.a(ssl.o) to 8 in ../lib/libssl.a(ssl_lib.o)
../lib/libssl.a(ssl_err2.o): In function `SSL_load_error_strings':ssl_err2.c:(.text+0x4): undefined reference to `ERR_load_crypto_strings'
../lib/libssl.a(ssl_algs.o): In function `SSL_library_init':ssl_algs.c:(.text+0x4): undefined reference to `EVP_des_cbc'
:ssl_algs.c:(.text+0xc): undefined reference to `EVP_add_cipher'
:ssl_algs.c:(.text+0x11): undefined reference to `EVP_des_ede3_cbc'
:ssl_algs.c:(.text+0x19): undefined reference to `EVP_add_cipher'
:ssl_algs.c:(.text+0x1e): undefined reference to `EVP_idea_cbc'
Have you tried using the libssl and libcrypto already installed in your /usr/lib directory (assuming you've installed the dev packages for both)? Once that compiles and runs without error using the default install, you can build your new libssl/libcrypto(?) from source, install to usr/local, and rebuild using the usr/local versions of the libraries.
You need to add the flag -lssl and -lcrypto in your makefile'
For example:
gcc somefile.c -o someprogram -lssl -lcrypto

Resources