c++gcckernelldi386

how to link a c++ library to a c++ source code when it has a specific linker script to compile?


i have these files:-

/lib
    kernel.hpp
    kernel.cpp
main.cpp

when i use

gcc -m32 -c main.cpp -lstdc++ -o main.o -llib/kernel.hpp

it says

[function name]([type of argument 1], [type of argument 2]) is not declared in this scope

how to fix?


Solution

  • I started writing a comment, but got to be too long, so we'll make it an answer instead. I don't think it in fact will answer your question, but it may point you in the right direction.

    Let's clear up a misconception, c++ is not a superset of c; there are c constructs that c++ does not support. If your code is c++, you need to compile it with a c++ compiler. The problems you've been describing all indicate that compilation is failing; you're not at the point where the linker is involved. The compile command you provided in your question had a -c flag, which tells the compiler to stop after the compilation step - so there's no point in having a -lstd++ flag in addition. For the compiler to find kernel.hpp you need a -I flag which indicates the directory where kernel.hpp can be found. That's what I was suggesting in my first comment.

    To sum up, as shown in the original question, you're using the wrong compiler and the wrong flags for what you want to do.