Lua compilation link error - linker

When I try to compile a little lua program, I get these errors :
/usr/lib//liblua52.so: undefined reference to `dlsym'
/usr/lib//liblua52.so: undefined reference to `dlerror'
/usr/lib//liblua52.so: undefined reference to `dlopen'
/usr/lib//liblua52.so: undefined reference to `dlclose'
Of course, I link with -ldl. I have lua5.2-dev installed on my ubuntu.
If you need any more infos ask me.
Thanks!

When I try to compile a little lua program, I get these errors
No. You get these errors when you link the program.
The fix is to add -ldl at the end of your link line.

The easy way to get this error is to have your PLAT variable set wrong in the Makefile. You need to set it in the top level Makefile and the src/Makefile.
The legal values show up about 10 lines down from the definition.

Ensure -ldl is exactly at the end of your link line as Employed Russian mentioned

Related

Looking to use a library with example code for Open Quantum Safe

So I am trying to use following library: Open Quantum Safe
I am using windows linux subsystem, so I followed the linux setup. I think I followed all the steps correctly, as I didnt have any errors.
I next wanted to run the example provided here: example KEM
This example code is also in the repo.
When I run the command suggested at the bottom of the second link I get the following:
/usr/bin/ld: build/lib/liboqs.a(aes_ossl.c.o): in function OQS_AES128_ECB_load_schedule': aes_ossl.c:(.text.OQS_AES128_ECB_load_schedule+0x2b): undefined reference to EVP_CIPHER_CTX_new'
/usr/bin/ld: aes_ossl.c:(.text.OQS_AES128_ECB_load_schedule+0x39): undefined reference to EVP_aes_128_ecb' /usr/bin/ld: aes_ossl.c:(.text.OQS_AES128_ECB_load_schedule+0x4d): undefined reference to EVP_EncryptInit_ex'
/usr/bin/ld: aes_ossl.c:(.text.OQS_AES128_ECB_load_schedule+0x61): undefined reference to EVP_CIPHER_CTX_set_padding' /usr/bin/ld: build/lib/liboqs.a(aes_ossl.c.o): in function OQS_AES128_free_schedule':
aes_ossl.c:(.text.OQS_AES128_free_schedule+0x17): undefined reference to EVP_CIPHER_CTX_free' /usr/bin/ld: build/lib/liboqs.a(aes_ossl.c.o): in function OQS_AES128_ECB_enc':
aes_ossl.c:(.text.OQS_AES128_ECB_enc+0x71): undefined reference to EVP_EncryptUpdate' /usr/bin/ld: aes_ossl.c:(.text.OQS_AES128_ECB_enc+0x8c): undefined reference to EVP_EncryptFinal_ex'
/usr/bin/ld: aes_ossl.c:(.text.OQS_AES128_ECB_enc+0xa9): undefined reference to `EVP_CIPHER_CTX_free'
and another 50 or so lines of the same type of errors.
This error is clearly telling me it cannot find functions, or files that it needs to compile, but I am not sure why? Some of these functions I cannot even locate.
My guess is that I somehow built the files wrong, but I am unsure.
If anyone has any experience with this library, or maybe wants to help me with the specifics, please let me know.
Thanks.
As mentioned by #Tsyvarev, I was using a static library which is why it was not able to find the dependencies. Once I used the dynamic library I was able to run the code.
Specific answer if you are using this exact library:
cmake -GNinja .. -DBUILD_SHARED_LIBS=ON
I also had to set the Path to the .so file:
LD_LIBRARY_PATH=/usr/liboqs/build/lib
I also did ldconfig, not sure if that was necessary or not.

Linker Complains Undefined Reference Under MINIX3.2.1

As you may imagine, it's a homework of Operating Systems and I'm asked to add function key Shift+F7 to show the number of running process.
I read the source code of command ps on GitHub (MINIX version 3.2.1) and try to implement a function that can finish the task in file /usr/src/servers/is/dmp_kernel.c. However, when I try to run make, it complains about undefined reference like
dmp_kernel.o: In function `running_proc_num':
dmp_kernel.c:(.text+0x1e): undefined reference to `chdir'
dmp_kernel.c:(.text+0x42): undefined reference to `fopen'
dmp_kernel.c:(.text+0x72): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x8b): undefined reference to `fclose'
dmp_kernel.c:(.text+0xc4): undefined reference to `log10'
dmp_kernel.c:(.text+0xcc): undefined reference to `ceil'
dmp_kernel.c:(.text+0x119): undefined reference to `log10'
dmp_kernel.c:(.text+0x121): undefined reference to `ceil'
dmp_kernel.c:(.text+0x170): undefined reference to `fopen'
dmp_kernel.c:(.text+0x1bc): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x1d3): undefined reference to `fclose'
dmp_kernel.c:(.text+0x210): undefined reference to `wait'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've already include the headers like stdio.h, math.h, unistd.h, and sys/wait.h. In the answer to one Stack Overflow question, I learnt that the reason for this issue is that the linker doesn't link a complete C library under MINIX. However, I usually use CMake and really have no idea to solve such issue. I don't even know how to "explicitly" link the functions using make.
I really look forward for your help!
The Makefile looks like
.include <bsd.own.mk>
PROG= is
SRCS= main.c dmp.c dmp_kernel.c dmp_pm.c dmp_fs.c dmp_rs.c dmp_ds.c dmp_vm.c
DPADD+= ${LIBSYS}
LDADD+= -lsys
MAN=
BINDIR?= /sbin
CPPFLAGS.dmp_kernel.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_rs.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_vm.c+= -I${NETBSDSRCDIR}
# This setting must match the kernel's, as it affects the IRQ hooks table size.
.if ${USE_APIC} != "no"
CFLAGS+= -DUSE_APIC
.endif
.include <minix.service.mk>

Failing to compile a 15+ year old MUD codebase written in C

I used this codebase to run a mud in the early 2000s, and through that, to teach myself some very elementary coding.
I just got a copy of the codebase from the administrator/coder who ran the server before me, and I'm just about certain that it would compile as-is back then, but now it won't.
My only guess is that it has something to do with updates to GCC in the last 15-20 years, but I'm admittedly a novice and pretty out of my depth here.
This is the error I get after about a hundred pages of warnings when I try to compile it using make:
[18:24:54] finger.c ...
In file included from finger.c:10:0:
../src/include/merc.h:5149:13: warning: inline function ‘check_toughness’ declared but never defined
inline int check_toughness args( ( CD *ch, CD *victim, int dam));
^~~~~~~~~~~~~~~
[18:24:54] Linking Executable ...
obj/fight.o: In function `group_gain':
tbw/reloaded/src/fight.c:5514: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5516: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5518: undefined reference to `xp_compute'
obj/fight.o: In function `one_hit':
tbw/reloaded/src/fight.c:2457: undefined reference to `check_toughness'
obj/mage.o: In function `do_chant':
tbw/reloaded/src/mage.c:345: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:361: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:377: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:393: undefined reference to `check_toughness'
obj/mage.o:tbw/reloaded/src/mage.c:409: more undefined references to `check_toughness' follow
obj/update.o: In function `mobile_update':
tbw/reloaded/src/update.c:756: undefined reference to `werewolf_regen'
obj/powerl.o: In function `do_planarstorm':
tbw/reloaded/src/powerl.c:680: undefined reference to `check_toughness'
collect2: error: ld returned 1 exit status
Makefile:27: recipe for target '../src/reloaded' failed
make: *** [../src/reloaded] Error 1
The codebase and the referenced files are huge, so I figured it wouldn't make sense to attach them just yet, but if required I can definitely provide them.
For the record, those functions like "check_toughness" and "xp_compute" are definitely defined within those files after a few thousand LOC.
Would appreciate any suggestions, thank you!
Thank you to everyone who came in with suggestions!
The simplest answer was provided by rici:
That is probably the result of the code using the old idiosyncratic gcc semantics for inline. Try compiling with --std=gnu89 (if you are using gcc).
Adding that to the Makefile cleared up all the errors and resulted in a successful compile.

undefined reference to '__imp_fmi2_import_free'

I have been trying to compile and link a test file written in c and which can communicate with FMILibrary of JModelica. I was able to compile and link it and run it in linux systems. coming to the Windows, I am using mingw-64 compiler to compile and link the test file with FMILibrary, but I am getting undefined reference errors. I was able to compile and run it on 32 bit mingw but I need to compile and link it with 64 bit compiled binaries.
My command goes like this:
gcc -I <..fmilib\include> -L <..fmilib\lib> -lfmilib -o testfile testfile.c fmivars.c
And the following is the result that is getting printed out as a result
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x9b): undefined reference to `__imp_fmi2_import_get_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0xd6): undefined reference to `__imp_fmi2_import_get_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x111): undefined reference to `__imp_fmi2_import_get_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x14c): undefined reference to `__imp_fmi2_import_get_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x187): undefined reference to `__imp_fmi2_import_set_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1c2): undefined reference to `__imp_fmi2_import_set_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1fd): undefined reference to `__imp_fmi2_import_set_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x238): undefined reference to `__imp_fmi2_import_set_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x27a): undefined reference to `__imp_fmi2_import_new_discrete_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x2b6): undefined reference to `__imp_fmi2_import_collect_model_counts'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x30b): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x37e): undefined reference to `__imp_jm_vsnprintf'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x395): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x437): undefined reference to `__imp_jm_vsnprintf'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x556): undefined reference to `__imp_fmi2_import_get_version'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x575): undefined reference to `__imp_fmi2_import_get_types_platform'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x594): undefined reference to `__imp_fmi2_import_get_number_of_continuous_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x5a8): undefined reference to `__imp_fmi2_import_get_number_of_event_indicators'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x64a): undefined reference to `__imp_fmi2_import_instantiate'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x690): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6af): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6df): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x718): undefined reference to `__imp_fmi2_import_setup_experiment'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x733): undefined reference to `__imp_fmi2_import_enter_initialization_mode'
Is there any macro or anything set on the FMILibrary to compile with 64 bit mingw compiler on windows 64 bit? Thanks.
Assuming the library libfmilib.x.y.z provided the missing symbols then on the linker's/compiler's command line move it to the right of the .c-files requiring them
gcc -I <..fmilib\include> -L <..fmilib\lib> -o testfile testfile.c fmivars.c -lfmilib
Thank you everyone for helping me. I finally solved my problem and was able to run the code. I installed dependency walker as suggested by #PilouPili and found out that my application is looking for the library in the same folder(I don't know for some reason) and it was unable to find it. So, I copied all the static and dynamic libraries and I pasted in the folder where my testfile is. Also I changed the command line as suggested by #alk and moved the -lfmilib to the end. And I used the dynamic library instead of static one. But anyways my application runs now. Thank you so much for helping out.

Struggling compiling a simple c program (gcc)

I have a very old C program and want to compile to Windows. So I try doing this:
gcc -DNO_GLIBC=1 sakide.c -o sakide.exe
and this returns:
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa4): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x6b6): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x8ff): undefined reference to `ekiEncodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x954): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x993): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa62): undefined reference to `ekiGetKeyInfo'
collect2.exe: error: ld returned 1 exit status
This ekiGetLibVersion is in a .h file:
INT EKIAPI ekiGetLibVersion(char *outBuffer, LPINT outBufferSize);
and I also have a .dll name of it.
Ive never compiled anything with C though
On windows you cannot link against directly with the .dll, you have to link the import library, name .lib. For more information, refer:
On dynamic linking:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682592(v=vs.85).aspx
On implicit linking:
https://msdn.microsoft.com/en-us/library/d14wsce5.aspx
You are getting linker errors.
You need to link the library (or object file) where those functions are defined.
Undefined reference usually means the compiler has not seen a proper declaration for this variable. Did you include the header file (which defines this variable) in your C program ?
#include "header_file.h"

Resources