file not recognized: File format not recognized error in C - c

Hey I am currently learning C and tried to divide my code in multiple files. But when it comes to compile the project, I got this error :
mingw32-gcc.exe -Wall -g -c D:\IDE\CodeBlocks\Projects\Tuto\main.c -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\Tuto.exe obj\Debug\dico.o dico.h.gch obj\Debug\main.o
dico.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
I tried to clean and/or rebuild my project but nothing goes through this issue. Can anyone help me please ??

dico.h.gch is a precompiled header. You aren't supposed to link it with your objects. Remove it from the line that creates Tuto.exe.

Related

DLL file format not recognized

So I've been trying to install the luasql-mysql module for a while now and I keep running into problems. This time when I go to install it gives me this error:
luasql-mysql 2.5.0-1 depends on lua >= 5.1 (5.3-1 provided by VM)
mingw32-gcc -O2 -c -o src/luasql.o -IC:\Program Files\lua-5.3.5\src src/luasql.c -
Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/ls_mysql.o -IC:\Program Files\lua-5.3.5\src src/ls_mysql.c -
Ic:/windows/system32/include
mingw32-gcc -shared -o luasql/mysql.dll src/luasql.o src/ls_mysql.o -Lc:/windows/system32 -
lmysqlclient C:\Program Files\lua-5.3.5\src/lua53.dll -lm
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lmysqlclient
C:\Program Files\lua-5.3.5\src\lua53.dll: file not recognized: file format not recognized
collect2.exe: error: ld returned 1 exit status
Error: Build error: Failed compiling module luasql/mysql.dll
I'm going to try reinstalling everything and hopefully that works but if anyone knows why I'm getting this problem then I would appreciate the help.

Is there a way to find the root of this error?

Im trying to compile some files with this given gcc command on a server cluster through Mac terminal:
gcc -o driver -std=c11 -Wall -W -ggdb3 driver.c ASMParser.c ParseResult.c Generate.o Grader.o
And get this error:
/usr/bin/ld:Grader.o: file format not recognized; treating as linker script
/usr/bin/ld:Grader.o:1: syntax error
collect2: error: ld returned 1 exit status
but its not very helpful considering Grader.o is a file I didn't even modify, it was provided by the teacher.
Any help on how to fix this? I have compiled it successfully using that gcc command before but after I added a few more implementation details in ASMParser.c it started giving me this error. Im expecting it to create a file called "driver" that I can run like this:
./driver "test file" "results.txt"

Linker issue in g++

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}")

DSO missing from command line although it is available

I am working with c++ code for a physics simulation, which uses a lot of external libraries (like GSL and cern`s ROOT). Trying to recompile project I encountered problems with linking. When running compilation of final file via:
g++ -fno-inline -O2 -fpic -o main.out ${ROOTINCS} main.o ext.o ${ROOTLIBS} $(objects2)
with :
objects2= many .o files made by us
ROOTLIBS=-L/usr/local/lib/root -lTree -lRIO -lNet -lHist -lMathCore -lCore -lGraf -lGraf3d -lGpad -lMatrix -lThread -lCint -lPhysics -lPostscript -lRint -lSpectrum -lg
ROOTINCS=-pthread -m64
I get annoying error:
/usr/bin/ld: /usr/local/lib/root/libHist.so: undefined reference to symbol 'gRandom'
/usr/local/lib/root/libMathCore.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The problem is nm -C run on libMathCore states 'gRandom' is declared there. Also -lMathCore is present in my command line.
When I run ld to check if it understands the flag:
ld -L/usr/local/lib/root -lMathCore --verbose 2>/dev/null
it does not complain and tries to link properly.
According to https://stackoverflow.com/a/24675715/3602168 order of libraries is correct in my linking (libHist uses libMathCOre and therefore is stated first).
Compilation runs under g++ 4.8.2 on ubuntu 14.04, 64 bit
Converting comment to answer:
Have you tried moving $(objects2) before ${ROOTLIBS}? I think the issue may be that you have libraries specified before the object files that use them.

Error occurs when compiling with GCC

I am attempting to compile a C program with multiple files on window platform. However, when I make it, errors are occurred. I have already tried to modify command in makefile but still could not fix it.
This is my GCC command:
gcc -o "SYSMONTR" $(OBJPATH)/chkdsksp ../chkdsksp.c -g -I"$(DB2PATH)/include" -I"$(MYLIBDIR)" $(MYIQDIR)/iqclilib.a $(OBJPATH)/icrou.a -lc -ldb2 -lnsl -L"$(DB2PATH)/lib"
This is result:
gcc -o "SYSMONTR" ../../iLINKOBJ/chkdsksp ../chkdsksp.c -g -I"C:/Program Files/IBM/SQLLIB/include" -I"../../iLINKCLIB" ../../iLINKIQOBJ/iqclilib.a ../../iLINKOBJ/icrou.a -lc -ldb2 -lnsl -L"C:/Program Files/IBM/SQLLIB/lib"
../../iLINKOBJ/chkdsksp: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
makefile:49: recipe for target `SYSMONTR' failed
make: *** [SYSMONTR] Error 1
What could cause such error and what should I do with it? Using cygwin on Window (IDE: Eclipse).
Any supports will be appreciated.
If chkdsksp is an object file built by another team to run on AIX, you cannot expect it to function -- or even be recognized by your compiler -- on Cygwin. You must contact that team and get a) the source code or b) a version of the object file compiled for your platform (and tested).

Resources