Search code examples
c++architectureg++x86-64darwin

G++ warning: built for unsupported file format which is not the architecture being linked


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)


Solution

  • 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.