Using c library in c++ code with makefile -


i have c library made cluster.h , cluster.c. compiled gcc -c cluster.c.

i have use method of library in main class of c++ project. makefile use:

abundancebin: main.o profilemanager.o myhash.o mymalloc.o mystack.o mystringhash.o     g++ -o abundancebin main.o profilemanager.o myhash.o mymalloc.o mystack.o         mystringhash.o main.o: main.cpp     g++ -c main.cpp profilemanager.o: profilemanager.cpp     g++ -c profilemanager.cpp myhash.o: myhash.cpp     g++ -c myhash.cpp mymalloc.o: mymalloc.cpp     g++ -c mymalloc.cpp mystack.o: mystack.cpp     g++ -c mystack.cpp mystringhash.o: mystringhash.cpp     g++ -c mystringhash.cpp  clean:     -rm *.o abundancebin 

i tried import c library in main.cpp using after other imports:

#ifdef __cplusplus extern "c" { #endif #include <cluster.h> #ifdef __cplusplus } #endif 

but when compile make have response:

main.cpp:29:21: fatal error: cluster.h: no such file or directory #include <cluster.h> ^ compilation terminated. make: *** [main.o] error 1

if use "cluster.h" instead of have error:

main.o:main.cpp:(.text+0xf68): riferimento non definito "kmedoids" main.o:main.cpp:(.text+0xf68): rilocazione adattata per troncamento: r_x86_64_pc32 contro il simbolo non definito "kmedoids" /usr/bin/ld: main.o: bad reloc address 0x18 in section.xdata' collect2: error: ld returned 1 exit status make: * [abundancebin] error 1`

i tried copy code part need c library c++ project compiler reports many errors this:

error: invalid conversion ‘void*’ ‘int*’ [-fpermissive] vector = malloc(nnodes*sizeof(int));

the library files in same folder of project files. can help? thank you

if want add code wrote in c language, have #include like:

extern "c" {        #include "x264.h" } 

which tell compiler deal differently, , not necessary change code c++

1: add code as: #include <cluster.h> better change to: #include "cluster.h" different is, second 1 tell compiler first search header in current directory , in main c++ libraries directory

your error:

main.cpp:29:21: fatal error: cluster.h: no such file or directory 

is because can't find header, so, if cluster.h in same directory main.cpp, use #include "cluster.h" or can use -i. (which tell in current directory) or -i/address tell compiler header

when correct it, second error, believe because of code, , think because of code in main.cpp, , not have cluster code, suggest, try post code find out what's problem


Comments

Post a Comment

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Socket.connect doesn't throw exception in Android -

SPSS keyboard combination alters encoding -