Using g++ in Linux mint causing undefined reference to 'Class::Function' (collect2: error)

前端 未结 1 424
太阳男子
太阳男子 2020-12-12 07:08

Also stoi and exit(0) are both out of scope in stk.cpp and I don\'t know why.

Here is main.cpp

#include \"stk.h\"

int main()
{
    cout << \"R         


        
相关标签:
1条回答
  • 2020-12-12 08:02

    The problem is that you are not linking the code from stk.cpp when creating the executable.

    Solution 1: Compile the .cpp files first and then link.

    g++ -c main.cpp
    g++ -c stk.cpp
    g++ main.o stk.o -o test
    

    Solution 2: Compile and link both files in one step.

    g++ main.cpp stk.cpp -o test
    
    0 讨论(0)
提交回复
热议问题