Undefined Symbols for architecture x86_64: Compiling problems
There's no mystery here, the linker is telling you that you haven't defined the missing symbols, and you haven't.
Similarity::Similarity()
or Similarity::~Similarity()
are just missing and you have defined the others incorrectly,
void Similarity::readData(Scanner& inStream){
}
not
void readData(Scanner& inStream){
}
etc. etc.
The second one is a function called readData, only the first is the readData method of the Similarity class.
To be clear about this, in Similarity.h
void readData(Scanner& inStream);
but in Similarity.cpp
void Similarity::readData(Scanner& inStream){
}
Undefined symbols for architecture x86_64 error when using multiple files
in C++ if you want to compile some code that is located in more than one file, you have to tell explicitly to the compiler where to find certain function, in this case the function add
, so in order to achive this, you have to specify the files in to the compiler in this way:
g++ main.cpp add.cpp
and after the compiling, the compiler will generate a a.out
file with the compiled file, and to run it just do ./a.out
.
Probably, Atom, not being a IDE for c++, just tries to compile that file, and the C++ compile can't find the function add in a object file
(.o extension).
Another one: Undefined symbols for architecture x86_64:
Either there is a problem compiling the code for Process
, which you did not include, or you didn't tell g++ where to find the library to link to.
An "Undefined Symbol" type error means that the linker cannot find the compiled code for a symbol. (In this case Process::setWT
, Process::setTAT
, and Process::print
.) You need to tell g++ where to find the libraries to link to.
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
A brief overview of how code compiles with g++ is: 1) g++
compiles the code into object files and/or libraries, 2) ld
(the linker) links the object files and libraries into an executable.
This is simplified, but it is important to know that the linker needs to know what object files and libraries (compiled code, but not executables) to link together to create the executable file.
Undefined symbols for architecture x86_64: error of compilation
Main.cpp has a reference to Player.hpp but there is no reference to Player.cpp. Adding the line:
#include "Player.cpp"
Should solve this problem
What does the compile-time error Undefined symbols for architecture x86_64 mean?
When you compile the file, the compiler invokes the linker which tries to generate an executable. But it cannot because you didn't provide a function named main
which is the function that will be executed when your program is launched.
Either you don't want to run the linker because you want to compile several files separately then combine then. In that case, use the -c
flag to tell the compiler to skip the link stage.
Or either you want to execute the compiled file. Then you need to implement the function main
.
Related Topics
Difference in Initializing and Zeroing an Array in C/C++
"Proper" Way to Store Binary Data with C++/Stl
Columns Auto-Resize to Size of Qtableview
How to Fix: /Usr/Lib/Libstdc++.So.6: Version 'Glibcxx_3.4.15' Not Found
How to Install/Configure Opencv3.2.0 with C++, Visual Studio 2017
When to Use 'Asio_Handler_Invoke'
Calculating Factorial Using Template Meta-Programming
What Is a Good Easy to Use Profiler for C++ on Linux
Default Initialization of Pod Types in C++
C++: Difference Between Ampersand "&" and Asterisk "*" in Function/Method Declaration
Compile Lua Code, Store Bytecode Then Load and Execute It
Idiomatic Way to Declare C++ Immutable Classes
How to Initialize an Array in C++ Objects