c++ compilation problem

M

Marcelo

I have this problem whenever I try to compile a very trivial program:

[mmfernan@algopc151 HelloWorld]$ cc -G HelloWorld.c -o libHelloWorld.so
cc: unrecognized option '-G'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

[mmfernan@algopc151 HelloWorld]$ cc -g HelloWorld.c -o libHelloWorld.so
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

Do you have an idea?

thanks

Marcelo
 
J

John Harrison

Marcelo said:
I have this problem whenever I try to compile a very trivial program:

[mmfernan@algopc151 HelloWorld]$ cc -G HelloWorld.c -o libHelloWorld.so
cc: unrecognized option '-G'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

[mmfernan@algopc151 HelloWorld]$ cc -g HelloWorld.c -o libHelloWorld.so
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

Do you have an idea?

Only if you post the very trivial program, do you think we are psychic?

BTW this is a linking error not a compiler error. You could have made a
mistake in your program, but I think it is more likely you have made a
mistake in the compiler options you are using. But that would be a
compiler issue not a C++ issue.

john
 
N

nan.li.g

You were trying to make an so file. Try '-shared -fpic'
And pls post your program next time no matter how trivial it is.
 
R

Rolf Magnus

Marcelo said:
I have this problem whenever I try to compile a very trivial program:

[mmfernan@algopc151 HelloWorld]$ cc -G HelloWorld.c -o libHelloWorld.so

This compiles C, not C++.
cc: unrecognized option '-G'

What is the -G supposed to do? According to the manual page, this option is
specific to the "Renesas M32R/D" architecture. Are you sure you're
compiling for that architecture?
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

Well, it seems you are trying to create a shared library. But how is the
compiler supposed to know that if you don't tell it? It's searching for
your definition of a main() function because it wants to build an
executable.
How about reading your linker's documentation?
 
M

Marcelo

You were trying to make an so file. Try '-shared -fpic'
And pls post your program next time no matter how trivial it is.
Thanks man, it works when i put -shared. I am very new in this c++
world, but I like it. (I am trying to use the JNI between java and c++).

Thanks a lot

Marcelo
 
V

Victor Bazarov

Marcelo said:
I have this problem whenever I try to compile a very trivial program:

[mmfernan@algopc151 HelloWorld]$ cc -G HelloWorld.c -o
libHelloWorld.so cc: unrecognized option '-G'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
undefined reference to `main'
collect2: ld returned 1 exit status

[mmfernan@algopc151 HelloWorld]$ cc -g HelloWorld.c -o
libHelloWorld.so
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
undefined reference to `main'
collect2: ld returned 1 exit status

Do you have an idea?

Not sure what you're trying to do, but 'main' is a function every program
should contain to be a complete C++ program. Yours probably doesn't have
it. That's what the linker (ld) complains about.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top