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).
Related
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
I have the following .sh file (from here).
g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -I. -I./tensorflow
-I./tensorflow/bazel-tensorflow/external/eigen_archive -I./tensorflow/bazel-tensorflow/external/protobuf/src -I./tensorflow/bazel-genfiles -o main.o ./main.cpp
g++ -o Tutorial main.o -L./tensorflow/bazel-bin/tensorflow
-ltensorflow_cc
cp ./tensorflow/bazel-bin/tensorflow/libtensorflow* .
When I try to run this .sh file from terminal I got an error. Therefore I executed the commands one by one. First one worked fine and I saw that when I run the second command ( g++ -o Tutorial main.o -L./tensorflow/bazel-bin/tensorflow
-ltensorflow_cc) I get the following error.
/usr/bin/ld: main.o: undefined reference to symbol '_ZN10tensorflow3Env19NewRandomAccessFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPSt10unique_ptrINS_16RandomAccessFileESt14default_deleteISA_EE'
libtensorflow_framework.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I saw the answer here and I see it as closely related to mine. But I cannot figure out how to adapt it to my problem.
Can someone please help with this?
The linker is saying that the linkage requires shared library libtensorflow_framework.so (presumably because -ltensorflow_cc depends on it and requests it) but is not given in your commandline. This should be solved by adding -ltensorflow_framework at the end, with an additional -L option if necessary.
I was too getting the same error.
If you are using tensorflow 2, then you need to link .so.2 files. You should find them in the bazel build directory. For me it is :
/tmp/bazel/output/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow
I linked the files using the below in my CMAKE:
file(GLOB LIBRARIES "${bazel_bin}/tensorflow/*.so.2")
message("LIBRARIES = ${LIBRARIES}")
I'm trying to compile and link some .c file. I have been using Eclipse IDE for C/C++ developers, and in my local machine i can compile without problems. However, when i try to compile and link the same file in a RedHat OS (gcc version is 4.9.2-6 in this OS) i'm having problems. I get some warnings at compile time, but those are fine, i think, i just ignored and the application still runs fine. Here are the commands i executed and the associated output:
gcc -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -MMD -MP -MF"example.d" -MT"example.d" -o "example.o" "example.c"
warning: suggest parentheses around assignment used as truth value [-Wparentheses]
warning: implicit declaration of function ‘wait’ [-Wimplicit-function-declaration]
This generates two files, example.d and example.o. Then, i try to link them, without luck, with the following command:
gcc -Xlinker -L/usr/lib -lrt -static -pthread example.o -o example
/usr/bin/ld: cannot find -lrt
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
The commands are taken directly from the ones that Eclipse generates, and work just fine in my local computer (Ubuntu OS) but not in the RedHat environment. The last command didn't work, with and without the -L option. I suppose the directory in -L is fine, as i run, for example,
locate libpthread.so
And one of the locations i get is /usr/lib (also /usr/lib64, but neither work).
Any help will be greatly appreciated!! :)
If you try to link a static executable, it will look for the *.a versions of the libraries, not what you usually want. Remove the -static flag. Or you can install the static libraries if you really want to. It also should not be necessary to add -L/usr/lib explicitly.
I have got the object-file from source code using MinGW.
But on linking:
ld -o test.exe test.o
I get errors, for example the following:
undefined reference to printf
First, why are you using ld directly?
The following is an excerpt from the "GCC and Make" tutorial found at http://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html.
Compile and Link Separately
The above command compile the source file into object file and link with other object files (system library) into executable in one step. You may separate compile and link in two steps as follows:
// Compile-only with -c option
> g++ -c -Wall -g Hello.cpp
// Link object file(s) into an executable
> g++ -g -o Hello.exe Hello.o
Note g++ (you can substitute gcc if you are using C and not C++) is used both for compiling and linking. ld is not used at all.
The benefit of using g++ or gcc to link is that it will link with default libraries, such as the one you need to link with for printf, automatically.
To link with other libraries, you specify the library name with the -l parameter, as in -lmylib.
We can view commands ran by compiler via command
c99 -v test.o
We'll get some text. All after string which contains "COLLECT_CGG_OPTIONS" will be arguments of ld.
But size of executable file is much more then size of file got by previous way.
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