I'm using the OpenWrt toolchain to build a C++ application, which makes use of a C library but I doubt that's relevant.
I have two files file.h
(which contains a C++ class along with the implementation) and main.cpp
which makes use of that class.
First I tried creating an object from file.h
mipsel-linux-g++ -Wall -c -Ipath_to/staging_dir_mipsel/include -Ipath_to/staging_dir_mipsel/usr/incude file.h -o file.o
Which gives no error and creates the object file. I do the same thing with main.cpp
but had issues with linking them together.
When I run
mipsel-linux-readelf -h main.o
It returns the header of the elf object
When I run
mipsel-linux-readelf -h file.o
It returns
readelf: Error: Unable to read in 0x2d78 bytes of section headers
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
Any pointers? :)
gcc ... -c file.h -o file.o
It is exceedingly unusual to put C code into a header file, and attempt to compile it in above manner into object code.
In fact, it is so unusual, that GCC, given above command, doesn't do it. Instead, it compiles file.h
into a precompiled header (normally called .gch
, but forced to be called .o
by your unfortunate -o
option).
Therefore, it's not at all surprising that file.o
is not an ELF
file. Just run file file.o
and see if it prints GCC precompiled header (version 013) for C
or some such.
If you really intend file.h
to be compilable to an ELF object file.o
, name it file.c
instead.