Compiling MIPSpro C program using MIPSpro C++ compiler on SGI system

  • Thread starter Christopher M. Lusardi
  • Start date
C

Christopher M. Lusardi

Hello,

Can I run the subject line program using CC instead of cc? I attempted
to use the "-c" option and it told me things were undefined. Isn't this
CC option the same as the cc -c option?

Thank you,
Christopher Lusardi
 
J

Jeff Schwab

Christopher said:
Can I run the subject line program using CC instead of cc? I attempted
to use the "-c" option and it told me things were undefined. Isn't this
CC option the same as the cc -c option?

No. In general, the meanings of flags depend on your compiler; neither
"cc" nor "CC" is mentioned in the C++ standard; these are
platform-specific compilers. In general, CC is a c++ compiler, cc is a
C compiler, and the -c option tells the compiler to create an object
file, rather than a stand-alone executable.
 
C

Christopher M. Lusardi

Jeff Schwab said:
No. In general, the meanings of flags depend on your compiler; neither
"cc" nor "CC" is mentioned in the C++ standard; these are
platform-specific compilers. In general, CC is a c++ compiler, cc is a
C compiler, and the -c option tells the compiler to create an object
file, rather than a stand-alone executable.


Hello again, for clarification purposes, I would like to restate my
question!

When I link a cc compiled file with a CC compiled file, I am told the
c routine is undefined and I do not get a "a.out"! What can/should I
do? Here's an example consisting of two files followed by their
compilation :


/* -------- cut here file ta.c : --------- */
void test (int t);

main ()
{
int my_t;

my_t = 3;
test (my_t);
}

/* -------- cut here file tb.c : --------- */

#include <stdio.h>

void test (int t)
{
printf ("t is %d\n",t);
}

/* -------- cut here compilation : --------- */

%cc -c tb.c
No such feature exists (-5,116)

%CC ta.c tb.o
No such feature exists (-5,116)

ld32: ERROR 33 : Unresolved text symbol "test(int)" -- 1st
referenced by ta.o.
Use linker option -v to see when and which objects, archives
and dsos are loaded.
ld32: INFO 152: Output file removed because of error.


Thank you,
Christopher Lusardi


P.S.: My initial results when I search google is very negative?
 
R

red floyd

Christopher said:
[redacted]

/* -------- cut here file ta.c : --------- */
void test (int t);
extern "C" void test(int);
main ()
{
int my_t;

my_t = 3;
test (my_t);
}

/* -------- cut here file tb.c : --------- */

#include <stdio.h>

void test (int t)
{
printf ("t is %d\n",t);
}

/* -------- cut here compilation : --------- */
 
T

Thomas Matthews

Christopher said:
Hello again, for clarification purposes, I would like to restate my
question!

When I link a cc compiled file with a CC compiled file, I am told the
c routine is undefined and I do not get a "a.out"! What can/should I
do? Here's an example consisting of two files followed by their
compilation :


/* -------- cut here file ta.c : --------- */
void test (int t);

main ()
{
int my_t;

my_t = 3;
test (my_t);
}

/* -------- cut here file tb.c : --------- */

#include <stdio.h>

void test (int t)
{
printf ("t is %d\n",t);
}

/* -------- cut here compilation : --------- */

%cc -c tb.c
No such feature exists (-5,116)

%CC ta.c tb.o
No such feature exists (-5,116)

ld32: ERROR 33 : Unresolved text symbol "test(int)" -- 1st
referenced by ta.o.
Use linker option -v to see when and which objects, archives
and dsos are loaded.
ld32: INFO 152: Output file removed because of error.


Thank you,
Christopher Lusardi


P.S.: My initial results when I search google is very negative?

I believe this is a severe case of language mixup.
I compiled your files using GNU C compiler, "gcc" with no errors:

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ gcc -c tb.c

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ gcc ta.c tb.o

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ ls
a.exe ta.c tb.c tb.o

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ ./a.exe
t is 3


However, when I use the GNU C++ compiler, "g++" to compile
the ta.c file and link in the tb.o file, I get a similar
error to yours:

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ g++ ta.c tb.o
/cygdrive/c/DOCUME~1/TH009MA/LOCALS~1/Temp/ccwOY11k.o(.text+0x2c):ta.c:
undefined reference to `test(int)'
collect2: ld returned 1 exit status


I assume that on your system, "cc" is the C compiler and
"CC" is the C++ compiler.

The issue boils down to "name mangling". This is the art of
naming a function so it includes type information to support
function overloading. Research "name mangling" in the FAQ
and in this newsgroup.

You have two solutions: Stick with one compiler and one
language. Don't mix the two.

Or if you insist on mixing the languages, research and
understand 'extern "C"'. This tells the compiler that the
external reference has "C" language linkage (i.e. no
name mangling). Change file ta.c to:
extern "C"
{
void test (int t);
}

int main (void)
{
int my_t;

my_t = 3;
test (my_t);
}
*********************************************
TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ cat ta.c
extern "C"
{
void test (int t);
}

main ()
{
int my_t;

my_t = 3;
test (my_t);
}


TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ g++ ta.c tb.o

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ ./a.exe
t is 3

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top