Compile Link LUA5.1 Lib. Error in dev-cpp - lua

this is my dev-cpp compiler log:
rm -f main.o luaTest.exe'
gcc.exe -c main.c -o main.o -I"E:/Dev-Cpp/include" -I"E:/Lua/5.1/include"'
gcc.exe main.o -o "luaTest.exe" -L"E:/Dev-Cpp/lib" -L "E:/lua/5.1/lua5.1.lib"'
main.o(.text+0x34):main.c: undefined reference to 'luaL_newstate'
main.o(.text+0x48):main.c: undefined reference to 'luaL_openlibs'
main.o(.text+0xab):main.c: undefined reference to 'luaL_loadbuffer'
main.o(.text+0xd5):main.c: undefined reference to 'lua_pcall'
main.o(.text+0x11c):main.c: undefined reference to 'lua_tolstring'
main.o(.text+0x14e):main.c: undefined reference to 'lua_settop'
main.o(.text+0x161):main.c: undefined reference to 'lua_close'
collect2: ld returned 1 exit status'
make.exe: *** [luaTest.exe] Error 1'
I can compiling & linking my code success with code::blocks. I can't figure out what's wrong with dev-cpp.

The linking step looks off. The option -L (uppercase L) sets a search directory for libs referenced via -l (lowercase L). The last step tries to link to lua5.1.lib using -L instead of the correct -l.

I have found out what's wrong with dev-cpp.when you want to link lib file you must shut down the makefile generation in the compiler option

Related

MSYS2 : GCC with OpenMP library working but clang with OpenMP not working

I am getting below error while compiling code with clang compiler in MSYS2 terminal.
Same it working for GCC with OpenMP in MSYS2 environment.
gcc main.c -o main -fopenmp ---> working
clang main.c -o main -fopenmp ---> Not working I am getting below errors
Could anyone let me know what went wrong here?
$ clang main.c -o main -fopenmp
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x10): undefined reference to omp_get_max_threads'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x28): undefined reference toomp_set_dynamic'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x2d): undefined reference to omp_get_max_threads'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x34): undefined reference toomp_set_num_threads'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x49): undefined reference to __kmpc_fork_call'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0xeb): undefined reference to__kmpc_for_static_init_4'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x13d): undefined reference to omp_get_thread_num'
C:\msys64\mingw64\bin\ld: C:\msys64\tmp\main-f23226.o:main.c:(.text+0x175): undefined reference to__kmpc_for_static_fini'

linker option order causing opencv undefined references [duplicate]

I'm writing a small C program that uses librt. I'm quite surprised that the program won't compile if I place the link flag at the start instead of at the end:
At the moment, to compile the program I do:
gcc -o prog prog.c -lrt -std=gnu99
If I were to do the following, it will fail to find the functions in librt:
gcc -std=gnu99 -lrt -o prog prog.c
Yet, this works with other libraries. I found the issue when attempting to use a simple Makefile. make actually compiled prog.c without liking first (using -c flag) and then did the linking.
This is the Makefile:
CC = gcc
CFLAGS = -std=gnu99
LIBS= -lrt
LDFLAGS := -lrt
prog: prog.o
$(CC) -o prog prog.c -lrt -std=gnu99
The output I would get when typing make would be:
gcc -std=gnu99 -c -o prog.o prog.c
gcc -lrt prog.o -o prog
prog.o: In function `main':
prog.c:(.text+0xe6): undefined reference to `clock_gettime'
prog.c:(.text+0x2fc): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [buff] Error 1
I have now crafted a Makefile that puts the linking at the end of the gcc line, however I'm puzzled why it doesn't work if the linking flag is at the start.
I would appreciate if anybody can explain this to me. Thanks.
As the linker processes each module (be it a library or a object file), it attempts to resolve each undefined symbol while potentially adding to its list of undefined symbols. When it gets to the end of the list of modules, it either has resolved all undefined symbols and is successful or it reports undefined symbols.
In your case, when it processed librt, it had no undefined symbols. Processing proc resulted in clock_gettime being an undefined symbol. gcc will not go back and look in librt for the undefined symbols.
For that reason, you should always have your code first, followed by your libraries, followed by platform provided libraries.
Hope this helps.
From the ld (the GNU linker) documentation (http://sourceware.org/binutils/docs/ld/Options.html#Options):
The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.
So if you specify the library too early, the linker will scan it, but not find anything of interest. Then the linker moves on to the object file produced by the compiler and finds references that need to be resolved, but it has already scanned the library and won't bother looking there again.

undefined reference to `LLVMLinkInInterpreter'

I'm trying to compile fibonacci.cpp from llvm's examples to test llvm 3.8 (installed from repo) on my system (4.6.4-1-ARCH)
I get the following error. I dug around to see what's missing in llvm-config parameters but I wasn't lucky.
Below, I provide the command run and its output:
[drunk#teapot LLVMPlayBox]$ clang++ fibonacci.cpp `llvm-config --cxxflags --ldflags --libs --system-libs engine` -o fibonacci
warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option]
1 warning generated.
/tmp/fibonacci-34ba2b.o: In function `_GLOBAL__sub_I_fibonacci.cpp':
fibonacci.cpp:(.text.startup+0x1): undefined reference to `LLVMLinkInInterpreter'
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)`
I also used -v to see more details but skipping most of it since it's lengthy:
....
1 warning generated.
"/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o fibonacci /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/crtbegin.o -L/usr/lib -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1 -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/fibonacci-5ea4ee.o -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils -lLLVMBitWriter -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lrt -ldl -lcurses -lpthread -lz -lm -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/crtend.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.1/../../../../lib64/crtn.o
/tmp/fibonacci-5ea4ee.o: In function `_GLOBAL__sub_I_fibonacci.cpp':
fibonacci.cpp:(.text.startup+0x1): undefined reference to `LLVMLinkInInterpreter'
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)`
Edit:
I tried as suggested but I got more errors now.
clang++ `llvm-config --cxxflags --ldflags --system-libs --libs engine interpreter` fibonacci.cpp -o fibonacci
warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option]
1 warning generated.
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x333): undefined reference to `ffi_type_pointer'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x386): undefined reference to `ffi_type_sint64'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x397): undefined reference to `ffi_type_sint32'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function
.......
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd52): undefined reference to `ffi_type_sint64'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd5e): undefined reference to `ffi_type_double'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd6a): undefined reference to `ffi_type_sint32'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd7b): undefined reference to `ffi_type_sint8'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd87): undefined reference to `ffi_type_sint16'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd93): undefined reference to `ffi_type_float'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function
.....
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x1368): undefined reference to `ffi_type_float'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x1374): undefined reference to `ffi_type_void'
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
Edit #2:
I added -lffi as suggested and it worked. So the command issued is:
clang++ fibonacci.cpp `llvm-config --cxxflags --ldflags --system-libs --libs engine interpreter ` -lffi -o fibonacci
LLVMLinkInInterpreter is part of libLLVMInterpreter, which is not included in your llvm-config command. To fix the problem you simply need to extend your build script as following:
llvm-config --cxxflags --ldflags --system-libs --libs engine interpreter
Notice --libs interpreter at the end.

Symbols not found in libusb

Note that I am new to iOS (actually, iDevices) internals.
I'm trying to compile iRecovery,
a tool used to communicate with iBoot, iOS's bootloader. Sadly... I'm getting errors about libusb while compiling :
./configure: line 15323: syntax error near unexpected token `libusb,'
./configure: line 15323: `PKG_CHECK_MODULES(libusb, libusb-1.0 >= 1.0.3)'
libusb is installed :
$> pkg-config --libs libusb
-L/opt/local/lib -lusb
$> pkg-config --libs libusb-1.0
-L/opt/local/lib -lusb-1.0
I tried to comment out the line that checks for libusb, but then I get a bunch of not found symbols, such as :
"_libusb_set_configuration", referenced from:
_irecv_open_with_ecid in libirecovery_la-libirecovery.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My simple question is... WHY ?!
Thanks for any help...
Okay, so here's a dirty workaround :
open (NOT RUN) autogen.sh file, and comment out the "PKG_CHECK_MODULES(libusb, libusb-1.0 >= 1.0.3)" line
save
run autogen.sh modified file provided
open the makefile located in /src : add "-lusb-1.0 -L/usr/local/lib/ -I /usr/local/include/ - I /usr/local/include/libusb-1.0" to the "GLOBAL_CFLAGS" variable
save
cd to main directory (parent of /src)
make
make install
Once done, your should be able to run irecovery from your shell.
Please note that it is not really clean, and that it is only confirmed to work for iRecovery.
But - It Works !

adding linker to command line

I am trying to compile a project and you can find the makefile at this link here https://dl.dropbox.com/u/95042389/Makefile
I have installed ANN and OpenCV 2.3.1.
When I type make, it is returning the errors given below.
sai#sai-HP-EliteBook-8460w:~/workspace/4pcs$ make
g++ -L/home/sai/workspace/OpenCV-2.4.1/lib -L/home/sai/workspace/ann_1.1.2/lib -L/usr/lib 4pcs.o 4pcs_test.o -o 4pcs -lopencv_highgui -lANN -o 4pcs
/usr/bin/ld: 4pcs.o: undefined reference to symbol 'cv::operator*(cv::Mat const&, cv::Mat const&)'
/usr/bin/ld: note: 'cv::operator*(cv::Mat const&, cv::Mat const&)' is defined in DSO /usr/lib/libopencv_core.so.2.3 so try adding it to the linker command line
/usr/lib/libopencv_core.so.2.3: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make: * [4pcs] Error 1
Then I tried this
sai#sai-HP-EliteBook-8460w:~/workspace/4pcs$ echo $LD_LIBRARY_PATH
/usr/lib:/opt/ros/fuerte/lib:/opt/ros/fuerte/lib:/usr/lib/libopencv_core.2.3
Still the same errors..
Any suggestions?
It was solved by adding
-lopencv_core and then it worked with no errors.

Resources