Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking problem in dynamic library while mixing C C++ code

Tags:

c++

c

gcc

dylib

I had a C dynamic library, due to some requirement change I have to do some refactoring.

I had following code in one c file.

__attribute__((noinline))
static void *find_document(...)
{
  ...
}

bool docuemnt_found(const char *name) {
 ...
    find_document(...);
 ...
}

I separated the docuemnt_found() function in different cpp file. Now docuemnt_found() function cannot link to find_document() method?

I tried creating header for the c file and then include header using extern "C" but it did not work.

I want to keep find_document() inline. Is there anything missing here or something wrong?

like image 214
RLT Avatar asked Jun 02 '26 03:06

RLT


1 Answers

The problem here is the declaration of the function as static - in C, this says that it should be available to other functions within the same compilation unit (.c file), but not to other functions outside the file. Removing static should solve the problem.

Incidentally, the second function is misspelled - it should be document_found, not docuemnt_found.

like image 107
Jon Bright Avatar answered Jun 05 '26 00:06

Jon Bright