+2  A: 

The easiest way to avoid undefined symbols while linking is to link with g++ (not gcc). You can still compile your .c file with gcc, though.

Also please use system at a time. The link error may go away if you run all your gcc and g++ commands on the same system (no matter the old or the new one).

pts
This is what I did:g++ -c -fPIC -Wall -Wuninitialized -fno-exceptions -fno-rtti -O -D__hpuxita -mlp64 -I$(INCLUDEPATH) $< ;gcc -c -fPIC -Wall -Wstrict-prototypes -Wuninitialized -O -D__hpuxita -mlp64 -I$(INCLUDEPATH) $< ;gcc -AA -Aa -mlp64 -shared -L$(LIBPATH) $(OBJS) -o $(APP)
PoorLuzer
Ah yes - all compilation is done on a single machine.
PoorLuzer
+1, the problem is the last line there, you should link with g++ not gcc which will include all the neccessary c++ stuff by default.
Evan Teran
Evan, yes, but then would not the resulting binary be a C++ binary with mangled names etc? I would want the resulting binary to be a C one. I want to use C++ only in specific instances where using the STL would be extremely beneficial, but the resulting binary needs to be C compatible.
PoorLuzer
The message 'Unable to find library 'libstdc++.so' is stopping all the fun now - maybe if I can locate the lib myself, the executable will now finally run?
PoorLuzer
Funny thing is even if I set SHLIB_PATH, LD_LIBRARY_PATH_64, LD_LIBRARY_PATH and, hell, even PATH to point to the .so file, I STILL get the error message!
PoorLuzer
+2  A: 

To call a C++ function from C, you can't have mangled names. Remove the conditional test for __cplusplus where you do the extern "C". Even though your functions will be compiled by a C++ compiler, using extern "C" will cause it to avoid name-mangling.

Here is an example:

The C file.

/* a.c */
#include "test.h"

void call_cpp(void)
{
  cpp_func();
}

int main(void)
{
  call_cpp();
  return 0;
}

The header file.

/* test.h */
#ifndef TEST_H
#define TEST_H
extern "C" void cpp_func(void);
#endif

The CPP file.

// test.cpp
#include <iostream>
#include "test.h"

extern "C" void cpp_func(void)
{
  std::cout << "cpp_func" << std::endl;
}

The compiler command line.

g++ a.c test.cpp
Dingo
and I should use gcc instead of g++ to link - unlike what Evan told above?
PoorLuzer
removing the conditional test to get no name mangling seems to mess with the prototype declaration in the header file because gcc barks at me "warning: implicit declaration of function 'TokenizeC'"
PoorLuzer
The conditional works only for C++, where it SHOULD work... I believe that is not the issue.
PoorLuzer
Added example to demonstrate how it's done.
Dingo
Why do I need to have the extern at both places - the source and the header? Is not having it in the header enough?
PoorLuzer
The declaration and definition must match. That's the reason you got the: "warning: implicit declaration of function 'TokenizeC'".
Dingo