Quote:
Originally Posted by Mactub
I don't have missed functions instead I have some other C/C++ connected errors, when I am using g++ compiler like this
g++ -g rand.c -lasound -li2cbrdg -o rand.o
it does not see functions inside that library but everything fine with c++ code.
How can I make g++ behave like gcc in this case?
|
Hey,
it sounds like you hit a name mangling issue. When using g++, you call the C++ compiler (cc1cplus), while you call the C compiler (cc1) when using gcc. Though with the C++ compiler, if you call a function like
int func(int, long int)
from your code, the C++ compiler will name mangle the symbol and finally tries to call a function named
_Z4funcil
which the linker then couldn't find in the libraries, because the libraries only have the function symbol 'func'. Though, if you really have C++ code in your source file rand.c, you should first of all change the extension to .cpp or .cc to make it in general clearer that this is C++ code. Then you should check the prototypes of the library functions and surround them by a
extern "C" {
<function prototypes>
}
This instructs the C++ compiler to NOT name mangle the functions listed in the extern "C" block.
I hope this is what you're searching for, otherwise, please post your concrete error message with a small source code example ...
- Andi -