By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,131 Members | 1,821 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,131 IT Pros & Developers. It's quick & easy.

Complation problem involving namespaces.

P: n/a
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.

--
Want to email me? remove both dashes from the email address.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Frederick Reeve" <fr*********@woodland-i.org> wrote in message
news:pa****************************@woodland-i.org...
| 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
--
http://ivan.vecerina.com
Jul 22 '05 #2

P: n/a
> 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.

--
Want to email me? remove both dashes from the email address.
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.