A
A
Alexey Zus2015-09-03 09:33:02
linux
Alexey Zus, 2015-09-03 09:33:02

Compiling C++ code. What option to specify?

Good day!
When describing the logic of class element-functions in another file with the .cpp extension, the compiler issues a message.
main.cpp:(.text+0xa1): undefined reference to `Students::sentName(std::string)'
main.cpp:(.text+0xd0): undefined reference to `Students::sentLName(std::string) )'
main.cpp:(.text+0x162): undefined reference to `Students::sentNums(int*)'
main.cpp:(.text+0x182): undefined reference to `Students::sentBall(float)'
main .cpp:(.text+0x194): undefined reference to `Students::getName()'
main.cpp:(.text+0x1e7): undefined reference to `Students::getLName()'
main.cpp:(.text +0x233): undefined reference to `Students::getBall()'
collect2: error: ld returned 1 exit status
They say you need to specify an option.
As I understand it, the compiler writes that there are no links.
I am using GCC g++.
Who knows a way out of the situation, help.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2015-09-03
@lexzus07

Formally, you forgot to tell the compiler that you have not one cpp, but two. The linker does not find the body of the methods, so it swears.
You can simply list all your files to the compiler on the command line.
Better, you need to use the build system. The Makefile is there, that's all.
In fact, you should finally start using ide. ide does all this automatically.

D
dponyatov, 2015-09-05
@dponyatov

Is there a full text of the command line to run the compiler?
In the simplest case, this is something like

g++ $(CXXFLAGS) -o program$(EXE) main.cpp module1.cp module2.cpp

But in your case, if the project is built from several files through the IDE, this may turn out to be some more complex problem, for example, a linker error in processing function/method names changed by the mangler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question