Most likely culprit is that you've either not defined the function or you included the library with the definition in the wrong order. [source]
In my case it was a bit more insidious - I was the victim of name mangling. Long story short, be extra careful when mixing C and C++. [solution]
The sad thing is I more or less encountered this problem 6 months ago, but I think I have a better understanding of it now.
Showing posts with label gcc. Show all posts
Showing posts with label gcc. Show all posts
Thursday, 23 June 2016
Tuesday, 17 November 2015
Mixing C and C++
First, use g++ as it can compile C++ AND C - gcc cannot do that. If for whatever reason you need to use gcc, then just make object files to link with using g++ and the cpp files.
If you're using malloc and get an error like this,
Linker complains that a function doesn't exist when it does. First verify with nm that the function does indeed exist. You can use it on .o object and .a archive (static library) files. If it does, the your problem is you're trying to include a header for a C file in a C++ file. There's some problems with not enough information being generated from the C file compared to what the C++ file needs. See this SO Q&A for a solution
If you're using malloc and get an error like this,
Process.cpp:45:53: error: invalid conversion from void* to char* [-fpermissive]it's because you need to cast the return value in C++ but not C. See this SO Q&A
char *linkCopy = malloc(strlen(&line[count]) + 1);
Linker complains that a function doesn't exist when it does. First verify with nm that the function does indeed exist. You can use it on .o object and .a archive (static library) files. If it does, the your problem is you're trying to include a header for a C file in a C++ file. There's some problems with not enough information being generated from the C file compared to what the C++ file needs. See this SO Q&A for a solution
Subscribe to:
Posts (Atom)