Complation problem involving namespaces.

F

Frederick Reeve

Hey all I have a little compilation problem I think is related to name
spaces but being new to C++ still I don't know the program
(http://rafb.net/paste/results/f1416037.html) when it is being linked
returns with "undefined reference to foo" for function in a C lib i have
linked... any Ideas?

I am attempting to link a C lib and I think the complication comes in here
also.

If it would be better I can post the program in another message. Its only
153 lines. The program in the opening comments includes the command I use
to compile this and the c version of it. The C version compiles fine by
the way.

Thanks for being there guys.
 
I

Ivan Vecerina

| Hey all I have a little compilation problem I think is related to name
| spaces but being new to C++ still I don't know the program
| (http://rafb.net/paste/results/f1416037.html) when it is being linked
| returns with "undefined reference to foo" for function in a C lib i have
| linked... any Ideas?
|
| I am attempting to link a C lib and I think the complication comes in here
| also.
.....
| The C version compiles fine by the way.

To include C headers from a C++ program, you need to place them
within an extern "C" block:
extern "C" {
#include <SomeCHeader.h>
}
This is because the C++ compiler uses name mangling (encoding the type
of the parameters into the link name of a function) to allow function
overloading. This mangling is disabled within the extern "C" block...


Cheers,
Ivan
 
F

Frederick Reeve

To include C headers from a C++ program, you need to place them
within an extern "C" block:
extern "C" {
#include <SomeCHeader.h>
}
This is because the C++ compiler uses name mangling (encoding the type
of the parameters into the link name of a function) to allow function
overloading. This mangling is disabled within the extern "C" block...

Thanks a lot Ivan That took care of the problem.

Frederick.
 

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

Similar Threads

Compile Problem involving Dependencies 7
Infinite loop problem 1
namespaces 4
What about namespaces ? 52
Getchar() problem 8
typedefs and namespaces 2
Logic Problem with BigInteger Method 2
Java problem 1

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top