0

So I am trying to create a exec with g++. My command is as follows:

g++ -o project21  main.cpp tools.hpp file.hpp FileInfo.cpp file.cp tools.cpp 

I get an error

ld: warning: ignoring file tools.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: ignoring file file.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)

The behavior here is that odd is that I can compile it in XCode and using the exec just fine it is just in the shell that I am having the problem.

Joe Tyman
  • 1,417
  • 5
  • 28
  • 57

2 Answers2

1

You don't need to compile the hpp files. Include them in your .cpp files.

Even if you include the hpp on your project, Xcode won't compile them, unless you explicitly ask it to (my mac is at work, but if I recall click the project (root of the tree at the left), click a target and check the tab build phases, there is a list with the files to compile).

About the segmentation fault, if it were missing source files (i.e, you added code in the .hpp files that really should be on a .cpp file), then you would get a link error, and not a segmentation fault. There are other reasons to the segmentation fault, run on GDB and debug it (compile with -g to be able to debug). Here are some possibilities:

  • If you are building for a different platform, the problem may be some platform specific code.
  • Compiler incompatibility: assuming you were using Xcode with LLVM, you may have some code that works with LLVM but behave different with gcc. Very unlikely (by my experience with those compilers, I can say they are very compatible), but still possible.
fbafelipe
  • 4,862
  • 2
  • 25
  • 40
0

Try deleting any *.gch files that may have been created by the Xcode build before trying your g++ command.

However, in general I'd try to get things working without pre-compiling the header files first, then add the pre-compiled header optimization if it's necessary (i.e., don't pass the .hpp files to the compiler explicitly until you've got everything else working and only if you really need to).

Michael Burr
  • 333,147
  • 50
  • 533
  • 760