A question on linking

M

main()

I have a C file that needs to be linked with a C++ library.
If i link using gcc, i get some unresolved references error.
If i link using g++,its getting linked perfectly.
Is it ok to link a C file with a C++ library with g++?
What are its implications?

if you think its off topic please indicate right channels.
 
P

Papastefanos Serafeim

I believe it's ok to link it with the C++ linker.

The C linker isn't working because the C++ library function
names are mangled to support polymorphism. The C++
linker is aware of the C++ function name mangling and
thus you are able to do the linking with the C++ linker.
 
T

Tim Prince

main() said:
I have a C file that needs to be linked with a C++ library.
If i link using gcc, i get some unresolved references error.
If i link using g++,its getting linked perfectly.
Is it ok to link a C file with a C++ library with g++?
What are its implications?

if you think its off topic please indicate right channels.
It would be more on topic on gcc-help list, or a forum dedicated to the
operating system of your choice. It's likely that you would get the
same effect by using the C compiler to link, specifying the necessary
libraries explicitly.
 
K

Keith Thompson

main() said:
I have a C file that needs to be linked with a C++ library.
If i link using gcc, i get some unresolved references error.
If i link using g++,its getting linked perfectly.
Is it ok to link a C file with a C++ library with g++?
What are its implications?

if you think its off topic please indicate right channels.

Your question is about the compiler(s), not about the language(s).
Try gnu.gcc.help.
 
S

SM Ryan

# I have a C file that needs to be linked with a C++ library.
# If i link using gcc, i get some unresolved references error.
# If i link using g++,its getting linked perfectly.
# Is it ok to link a C file with a C++ library with g++?
# What are its implications?

You might try using a C++ construct that looks something like
external "C" {...}
(check with C++ for the actual syntax) to interface C and C++.
 

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

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top