This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

-ffreestanding option.


Dear gcc users,

I would like to submit a problem that I'm facing with gcc 2.95 (Linux
version and Cygwin version). It is possible that somebody has an idea.

I am trying to compile a shared library in which one of the exported
symbol must be a function returning a pointer. This function is expected 
to be call "main". I have no control over the hosting application,
therefore, I can not change the name of the exported symbol.

/* *** my_prog.cpp ********* */

class Foo {
private:
  int private_data;
public:
  Foo(void) {private_data=0;}
};

Foo *main(void)
{
  return new Foo();
}

/* ************************ */

In order to build the object file from the source code, I use the
"-ffreestanding" option in gcc which implies that main has no special
requirements.

However, the result of compilation seems to indicate that gcc has not
taken into account the option (and the source code will not compile).
I have a similar bad result with gcc on Linux and Windows.

Is it possible that this option is not supported anymore in gcc or
that it exists another mean within gcc in order to use the "main" 
symbol without the usual builtin requirement.

/**** LOG *****/

> g++ -v -ffreestanding -c -o myprog.o myprog.cpp
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)
 /usr/lib/gcc-lib/i386-linux/2.95.2/cpp -lang-c++ -v -D__GNUC__=2
-D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix
-D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix
-D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386)
-Di386 -D__i386 -D__i386__ myprog.cpp /tmp/ccHov674.ii
GNU CPP version 2.95.2 20000220 (Debian GNU/Linux) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-lib/i386-linux/2.95.2/../../../../include/g++-3
 /usr/local/include
 /usr/lib/gcc-lib/i386-linux/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search
path:
 /usr/lib/gcc-lib/i386-linux/2.95.2/../../../../i386-linux/include
End of omitted list.
 /usr/lib/gcc-lib/i386-linux/2.95.2/cc1plus /tmp/ccHov674.ii -quiet
-dumpbase myprog.cc -version -ffreestanding -o /tmp/ccWJqTXZ.s
GNU C++ version 2.95.2 20000220 (Debian GNU/Linux) (i386-linux) compiled
by GNU C version 2.95.2 20000220 (Debian GNU/Linux).
myprog.cpp: In function `int main(...)':
myprog.cpp:10: return to `int' from `Foo *' lacks a cast


> g++-2 -v -mno-cygwin -ffreestanding   -c -o myprog.o myprog.cpp
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-10/specs
gcc version 2.95.3-10 (cygwin special)
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-10/cpp0.exe -lang-c++ -v
-D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D_X86_=1
-D_X86_=1 -Asystem(winnt) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386)
-Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__
-D__pentiumpro -D__pentiumpro__ -D__stdcall=__attribute__((__stdcall__))
-D__fastcall=__attribute__((__fastcall__))
-D__cdecl=__attribute__((__cdecl__))
-D_stdcall=__attribute__((__stdcall__))
-D_fastcall=__attribute__((__fastcall__))
-D_cdecl=__attribute__((__cdecl__))} -D__declspec(x)=__attribute__((x))
-D__MSVCRT__ -D__MINGW32__ -isystem /usr/local/include/mingw -isystem
/usr/local/include/mingw -idirafter /usr/include/mingw -DWIN32 -DWINNT
-D_WIN32 -D_WIN32 -D__WIN32 -D__WIN32__ -idirafter /usr/include/w32api
-isystem /usr/include/mingw/g++-3 -isystem /usr/include/mingw/g++
myprog.cpp /tmp/ccooohtc.ii
GNU CPP version 2.95.3-10 (cygwin special) (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/mingw/g++-3
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-10/include
 /usr/include/mingw
 /usr/include/w32api
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-10/cc1plus.exe /tmp/ccooohtc.ii
-quiet -dumpbase myprog.cc -mno-cygwin -version -ffreestanding -o
/tmp/cc4kWmmi.s
GNU C++ version 2.95.3-10 (cygwin special) (i686-pc-cygwin) compiled by
GNU C version 2.95.3-10 (cygwin special).
myprog.cpp: In function `int main(...)':
myprog.cpp:10: return to `int' from `Foo *' lacks a cast


-- 
We can produce the sound of       Stéphan TASSART 
2 hands clapping. Now, how     Tél: (33) 1 42 02 24 71
does one hand sound? (TaDream)    tassart at free dot fr


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]