G++ warning: built for unsupported file format which is not the architecture being linked
-
11-10-2019 - |
سؤال
Whenever I try to compile my project (with the command line g++ *.hpp *.cpp 2> log.txt
), that's what I get:
log.txt
:
ld: warning: in configfile.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in erase.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in filehandler.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in insert.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in operation.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
Any ideas of why this is happening? I'm under OSX 10.6 (using latest Developer Tools)
المحلول
You're compiling header files (.hpp) which you shouldn't do yet. Only compile source files (.cpp)
Rather than compiling all .cpp files, compile them one at a time and then link them appropriately.
g++ -c x.cpp
g++ -c y.cpp
g++ -c z.cpp
g++ -o tst x.o y.o z.o
Note that only one of your .cpp files can have a main() function - otherwise the OS won't know where the entry point is.
نصائح أخرى
I do not own a Mac so I'm kind of giving you the Linux version of what to do when this happens.
Look for a multilib version of gcc and recompile with the -m32 switch
g++ *.hpp *.cpp -m32
Try this. You CAN compile header files with gcc to produce pre-compiled headers.
The g++ parameter -arch i386
should do the trick for you:
g++ *.hpp *.cpp -m32 -arch i386
Is that correct?