Problem linking C code with C++

hercules

Disciple
Hello,
I was trying to write a shared library in c, and was using it in a .cpp file.
I tried in linux and in my .cpp file i included my shared library's header file with extern C statement, like
extern "C" {
# include <myfile.h>
}
and it worked well.

Now with the same set of files I was trying it on windows with Cygwin.
But i get an error saying the
undefined reference to `_myFunction' .

I am wondering how to tell the compiler on cygwin that my shared files are in c.
One difference with linux is that, with cygwin the linking is static, i have to create .a file rather than .so .

Any idea anybody please....

thank u
her...
 
yup since u r getting a linking error, ur C++ code is not able to find the definition of the C function. So make sure u r linking ur C library properly with a proper path.
 
Note the difference in using <> and " " for including files. If you type

Code:
#include<myfile.h>
the compiler usually searches for the header in the specified directory for the header files. If you use

Code:
#include "myfile.h"

it indicates that the header is located in the directory of the source.
 
+1 to kingkrool, -l<library> -L<path to library> -I<path to header> in the arguments to g++
 
Back
Top