Hello,
I'm just writing a bit c and c++, now a have a problem. I have a shared-object, compiled with gcc, and a program, compiled with g++. The program should call a function of the library.
But the linking doesn't work?
An example:
lib.c
Code:
#include "lib.h"
int kalk(int n1, int n2) {
return n1 + n2;
}
lib.h
Code:
#ifndef __MY_LIB
#define __MY_LIB
int kalk(int n1, int n2);
#endif
test.cpp
Code:
#include <iostream>
#include "lib.h"
using namespace std;
int main(void) {
cout << kalk(1, 2);
return 0;
}
Then i compile the library with the following command:
Code:
gcc lib.c -shared -olib.so
And the program itself with:
Code:
g++ test.cpp lib.so -otest
but this compilation failes:
Code:
/tmp/ccoYXf6C.o: In function `main':
test.cpp:(.text+0x19): undefined reference to `kalk(int, int)'
collect2: ld returned 1 exit status
If i compile the library with g++, then it works:
Code:
g++ lib.c -shared -olib.so
it should be possible to use c-librarys in c++, shouldn't it be? I don't know. I think i did something wrong.
Thanks for your help
best regards
toredo