J
Joe.pHsiao
Hi,
I tried to link a C program to a library which is written by me in C+
+.
I read some posts about linking a C program to C++ libraries. It seems
doable by adding extern "C" to the C++ head file and to the function
body modifier. However, in my test, it still doesn't work. The linking
error messages are like undefined reference for new operator, and
undefined reference from dequeue.tcc. ( sorry I don't know how to copy
lines from terminals under solaris.)
I used STL vector and queue in the library, and I guess they uses new
operator to put items inside them.
The C program fails to link if gcc is used.
If I use g++ to build the file, there's no problem.
So I thought the code in the C++ library should also be recognized in
C. Keywords like "new," " delete," and "vector" are not allowed.
But then I thought if the code is recognized in C is the first place,
what is extern "C" for?
Can somebody explain this to me? Thanks.
I tried to link a C program to a library which is written by me in C+
+.
I read some posts about linking a C program to C++ libraries. It seems
doable by adding extern "C" to the C++ head file and to the function
body modifier. However, in my test, it still doesn't work. The linking
error messages are like undefined reference for new operator, and
undefined reference from dequeue.tcc. ( sorry I don't know how to copy
lines from terminals under solaris.)
I used STL vector and queue in the library, and I guess they uses new
operator to put items inside them.
The C program fails to link if gcc is used.
If I use g++ to build the file, there's no problem.
So I thought the code in the C++ library should also be recognized in
C. Keywords like "new," " delete," and "vector" are not allowed.
But then I thought if the code is recognized in C is the first place,
what is extern "C" for?
Can somebody explain this to me? Thanks.