I am trying to create a stack and test it using Google tests in an experiment with the C++ Google Test framework. I have set up the structure so I have a stack.h and stack.cpp for the implementation then I have a tests.cpp with the following code. I have several questions: first, is it possible to call my test functions from the main as I have done? Also, am I including everything correctly? Why are the build errors happening? Sorry, I am new to C++ and thanks for the help in advance. Here is the code and errors:
#include "stack.h"
#include "gtest/gtest.h"
TEST (StackTest, PushAndPeek) {
Stack<int> intStack;
int a = 12;
int b = 15;
EXPECT_EQ (12, intStack.push(a));
EXPECT_EQ (15, intStack.push(b));
EXPECT_EQ (15, intStack.peek()); //make sure adding in LIFO Order
EXPECT_EQ (15, intStack.peek()); //Should still be there
}
TEST (StackTest, PushAndPop) {
Stack<int> intStack;
int a = 12;
int b = 15;
EXPECT_EQ (12, intStack.push(a));
EXPECT_EQ (15, intStack.push(b));
EXPECT_EQ (15, intStack.pop()); //make sure adding in LIFO Order
EXPECT_EQ (12, intStack.pop()); //Should have removed 15, then removed 12
EXPECT_EQ (-1, intStack.pop()); //Should return -1 because there is nothing on the stack
}
Then in my main.cpp I have:
#include <iostream>
#include <string>
#include "gtest/gtest.h"
#include "stack.h"
using namespace std;
int main(int argc, char * argv[])
{
string input;
cout << "Hey there! If you wanna run the tests, type in tests. \nOther wise just hit enter to continue...\n";
getline (cin, input);
if(input == "tests"){
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
return 0;
}
However, I am compiling using XCode and it is failing to build with the following reasons:
Undefined symbols for architecture x86_64:
"Stack<int>::pop()", referenced from:
StackTest_PushAndPop_Test::TestBody() in tests.o
"Stack<int>::peek()", referenced from:
StackTest_PushAndPeek_Test::TestBody() in tests.o
"Stack<int>::push(int&)", referenced from:
StackTest_PushAndPeek_Test::TestBody() in tests.o
StackTest_PushAndPop_Test::TestBody() in tests.o
"Stack<int>::Stack()", referenced from:
StackTest_PushAndPeek_Test::TestBody() in tests.o
StackTest_PushAndPop_Test::TestBody() in tests.o
"Stack<int>::~Stack()", referenced from:
StackTest_PushAndPeek_Test::TestBody() in tests.o
StackTest_PushAndPop_Test::TestBody() in tests.o
"testing::internal::EqFailure(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in tests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
EDIT:
By including the stack.cpp I resolved the errors related to that, but I still have the following errors:
Undefined symbols for architecture x86_64:
"testing::internal::EqFailure(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in tests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
At first sight that looks as if you had made a beginners mistake with templates: Templates have to be implemented in the header file, you cannot separate them in header and .cpp file like normal classes and functions. Just search for "undefined refernce" and "template" on SO and you will get a lot of information on that matter :-)
Related
I'm trying to run a simple c++ program that open a window using the SFML library in Xcode 13
#include <iostream>
#include <SFML/Window.hpp>
int main(int argc, const char * argv[]) {
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");
return 0;
}
When i try to run it under native arm64 at compile time show this error:
Undefined symbols for architecture arm64:
"sf::String::String(char const*, std::__1::locale const&)", referenced from:
_main in main.o
"sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
_main in main.o
"sf::Window::~Window()", referenced from:
_main in main.o
"sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And when I try to run it under rosetta (x86_64) show this:
Undefined symbols for architecture x86_64:
"sf::String::String(char const*, std::__1::locale const&)", referenced from:
_main in main.o
"sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
_main in main.o
"sf::Window::~Window()", referenced from:
_main in main.o
"sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Idk what to do, I'm new to c++. THANKS
Here is a very simple script using gtest (saved in file gt.cpp)
#include<gtest/gtest.h>
double timesTwo(double x){return x*2;}
TEST(testTimesTwo, integerTests){EXPECT_EQ(6, timesTwo(3));}
int main(int argc, char* argv[]){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The script compiles fine with CLANG (Apple clang version 11.0.3)
clang++ -std=c++17 -lgtest gt.cpp -o gt
but fails with GCC (g++ (GCC) 10.2.0)
g++ -std=c++17 -lgtest gt.cpp -o gt
gt.cpp:2:9: fatal error: gtest/gtest.h: No such file or directory
2 | #include<gtest/gtest.h>
|
Using the -H option in CLANG, I see the header file is included from /usr/local/include. Also, I can find the libgtest.a file in /usr/local/bin/. So, I did
g++ -std=c++17 gt.cpp -o gt -I/usr/local/include/ -L/usr/local/lib/ -lgtest
and got a long list of undefined symbols starting with
Macavity:test remi$ g++ -std=c++17 gt.cpp -o gt -I/usr/local/include/ -L/usr/local/lib/ -lgtest
Undefined symbols for architecture x86_64:
"__ZN7testing8internal9EqFailureEPKcS2_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_b", referenced from:
__ZN7testing8internal18CmpHelperEQFailureIidEENS_15AssertionResultEPKcS4_RKT_RKT0_ in ccrUwUPO.o
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4findEcm", referenced from:
__ZN7testing8internal11SplitStringERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEcPNS1_6vectorIS7_NS5_IS7_EEEE in libgtest.a(gtest-all.cc.o)
__ZN7testing8internalL21FormatDeathTestOutputERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in libgtest.a(gtest-all.cc.o)
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7compareEmmPKcm", referenced from:
Can you help me figure out why GCC fails to compile here?
Here is this error message passed through a http://demangler.com/
Undefined symbols for architecture x86_64:
"_testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)", referenced from:
_testing::AssertionResult testing::internal::CmpHelperEQFailure<int, double>(char const*, char const*, int const&, double const&) in ccrUwUPO.o
"_std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
_testing::internal::SplitString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*) in libgtest.a(gtest-all.cc.o)
_testing::internal::FormatDeathTestOutput(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
"_std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const", referenced from:
Note that second and third error complains that linker can't find implementation of: std::string::find(char, unsigned long) and std::string::compare(unsigned long, unsigned long, char const*, unsigned long) const.
Those are parts of standard C++ library. Since std::string is template some parts of it are part of library which uses that template, but is some cases it can be part of C++ runtime.
Now I suspect that you compiled gtest with a clang and try use it when building test with gcc (or vice versa). A bit different implementations of std::string on both compilers lead to divergence in available symbols.
So please make sure that gtest and test application are build with same compiler.
Here is some description of binary compatibility between gcc and clang. There are some hints what problem is, but it is not very formal (maybe I will find better document).
I followed the instruction on thier github https://github.com/openvinotoolkit/openvino to build it on macOS, done it and when i wrote a small code to check was all clear or not
#include <string>
#include <iostream>
#include <dlfcn.h>
#include <fstream>
#define USE_STATIC_IE
#define _CRT_SECURE_NO_WARNINGS
#include <ie_core.hpp>
using namespace :: std;
int main(){
dlopen("/Users/nk/Documents/HZ/openvino/inference-engine/temp/tbb/lib/libtbb.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libngraph.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_transformations.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_legacy.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_lp_transformations.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libMKLDNNPlugin.dylib", RTLD_LAZY);
const std::string pluginsFilePath = "/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/plugins.xml";
InferenceEngine::Core ie(pluginsFilePath);
const auto info = ie.GetVersions("CPU");
if(!info.empty())
cout << "Yes";
return 0;
}
when i compile it with command
g++ -std=c++11 -I/Users/nk/Documents/HZ/openvino/inference-engine/include testdll.cpp -o testdll && "/Users/nk/Documents/FelenaSoft/"testdll
it gave me the error
Undefined symbols for architecture x86_64:
"InferenceEngine::Core::Core(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in testdll-788073.o
"InferenceEngine::Core::GetVersions(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
_main in testdll-788073.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
then i added .a libs and ran this command
g++ -std=c++11 -L/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib -lmkldnn -lpugixml -linference_engine_s -I/Users/nk/Documents/HZ/openvino/inference-engine/include testdll.cpp -o testdll && "/Users/nk/Documents/FelenaSoft/"testdll
and i got this
Undefined symbols for architecture x86_64:
"ngraph::as_output_vector(std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&)", referenced from:
ngraph::Node::generate_adjoints(ngraph::autodiff::Adjoints&, std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&) in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::match_node(ngraph::pattern::Matcher*, ngraph::Output<ngraph::Node> const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::match_value(ngraph::pattern::Matcher*, ngraph::Output<ngraph::Node> const&, ngraph::Output<ngraph::Node> const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::constant_fold(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > >&, std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::set_arguments(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&)", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::set_output_type(unsigned long, ngraph::element::Type const&, ngraph::PartialShape const&)", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::m_next_instance_id", referenced from:
std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode> std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode>::make_shared<>() in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::validate_and_infer_types()", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::evaluate(std::__1::vector<std::__1::shared_ptr<ngraph::runtime::HostTensor>, std::__1::allocator<std::__1::shared_ptr<ngraph::runtime::HostTensor> > > const&, std::__1::vector<std::__1::shared_ptr<ngraph::runtime::HostTensor>, std::__1::allocator<std::__1::shared_ptr<ngraph::runtime::HostTensor> > > const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::~Node()", referenced from:
ExecGraphInfoSerialization::ExecutionNode::~ExecutionNode() in libinference_engine_s.a(ie_rtti.cpp.o)
ExecGraphInfoSerialization::ExecutionNode::~ExecutionNode() in libinference_engine_s.a(ie_rtti.cpp.o)
std::__1::__shared_ptr_emplace<ExecGraphInfoSerialization::ExecutionNode, std::__1::allocator<ExecGraphInfoSerialization::ExecutionNode> >::~__shared_ptr_emplace() in libinference_engine_s.a(ie_rtti.cpp.o)
std::__1::__shared_ptr_emplace<ExecGraphInfoSerialization::ExecutionNode, std::__1::allocator<ExecGraphInfoSerialization::ExecutionNode> >::~__shared_ptr_emplace() in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_dynamic() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::description() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_constant() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_arguments() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_size() const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::write_description(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::copy_with_new_args(std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&) const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_element_type(unsigned long) const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_default_output_index() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_partial_shape(unsigned long) const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_autob() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_output() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"typeinfo for ngraph::Node", referenced from:
typeinfo for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"vtable for ngraph::Node", referenced from:
std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode> std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode>::make_shared<>() in libinference_engine_s.a(ie_rtti.cpp.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did anyone had the same problem as me, and did anyone know how to fix it?
First and foremost just need to cross check with you on your toolkit installation. Since you are trying to run a model already, I assume you already set it up properly as in (fyi latest version is 2020.4): https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
The error that you are getting, the Undefined symbols for architecture x86_64 is an Xcode build failure indicating you missed out something in your inference engine or the way you link the model with certain resources are incorrect or some other reasons. As long as this error persist you won't be able to compile your code. That is why you got the linker command failed with exit code 1.
Most error occurs because the users did not Set the OpenVINO environment variables or Configure the Model Optimizer correctly. This is why it's really important to Run verification scripts to verify installation and compile samples.
Before running any custom model, it is good to have a solid working Openvino environment, hence please help to check whether you could run the default models as in example here https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
By default, you should already have pre-trained models including open zoo model, Model Optimizer and Inference Engine which are working example to work with if you configured the toolkit correctly. These should already located in your installed toolkit's directory which you don't have to install separately from other resources.
Please take a note that you need:
CMake 3.4 or higher,
Python 3.5 or higher,
Apple Xcode Command Line Tools*,
(Optional) Apple Xcode* IDE (not required for OpenVINO, but useful for development),
And supported MAC OS is macOS 10.14.4*
Again, please help to cross check what you have in your Openvino environment and steps you had used to configure with the official documentation https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
Thanks!
I am trying to integrate Catch unit testing to my project but it fails for the currently available
Catch v1.10.0
Generated: 2017-08-26 15:16:46.676990
Example:
test.cpp
#include "catch.hpp"
#define CATCH_CONFIG_MAIN
TEST_CASE("CATCH TEST"){
REQUIRE(1 == 1);
}
g++ test.cpp -o test.exe -std=c++11
Error:
Undefined symbols for architecture x86_64:
"Catch::ResultBuilder::endExpression(Catch::DecomposedExpression const&)", referenced from:
Catch::BinaryExpression<int const&, (Catch::Internal::Operator)0, int const&>::endExpression() const in test-b77427.o
"Catch::ResultBuilder::setResultType(bool)", referenced from:
Catch::BinaryExpression<int const&, (Catch::Internal::Operator)0, int const&>::endExpression() const in test-b77427.o
"Catch::ResultBuilder::useActiveException(Catch::ResultDisposition::Flags)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::ResultBuilder::react()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::ResultBuilder::ResultBuilder(char const*, Catch::SourceLineInfo const&, char const*, Catch::ResultDisposition::Flags, char const*)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::ResultBuilder::~ResultBuilder()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::SourceLineInfo::SourceLineInfo(char const*, unsigned long)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
___cxx_global_var_init in test-b77427.o
"Catch::isDebuggerActive()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"Catch::AutoReg::AutoReg(void (*)(), Catch::SourceLineInfo const&, Catch::NameAndDesc const&)", referenced from:
___cxx_global_var_init in test-b77427.o
"Catch::AutoReg::~AutoReg()", referenced from:
___cxx_global_var_init in test-b77427.o
"Catch::toString(int)", referenced from:
Catch::ExpressionLhs<int const&>::reconstructExpression(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-b77427.o
Catch::BinaryExpression<int const&, (Catch::Internal::Operator)0, int const&>::reconstructExpression(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-b77427.o
"Catch::ResultBuilder::shouldDebugBreak() const", referenced from:
____C_A_T_C_H____T_E_S_T____0() in test-b77427.o
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit
g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
As it stands your program does not have a main function. If you compile it, the linker will complain about the absence of a main function. Since you are writing unit tests using the catch framework, you want that framework to generate a main function for you.
The catch framework looks whether CATCH_CONFIG_MAIN is defined and if yes, it generates a main function for you which runs all the tests you define. Because compilation is a linear process, the macro CATCH_CONFIG_MAIN has to be defined before including catch.hpp. Otherwise, the library will never “see” this macro.
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("CATCH TEST"){
REQUIRE(1 == 1);
}
Live example
I'm trying to get some sample code to work happily with OpenMS and running into a great deal of trouble. I have (just a small sample program that shipped as an example):
#include <OpenMS/FILTERING/SMOOTHING/GaussFilter.h>
#include <OpenMS/FORMAT/MzMLFile.h>
#include <OpenMS/KERNEL/StandardTypes.h>
#include <stdio.h>
using namespace OpenMS;
using namespace std;
Int main(){
PeakMap exp;
MzMLFile mzdata_file;
mzdata_file.load("../sampledata_Centroidmode.mzML",exp);
GaussFilter g;
Param param;
param.setValue("gaussian_width",1.0);
g.setParameters(param);
g.filterExperiment(exp);
return 0;
}
And I compile it:
g++ -Wall -IOpenMS-1.7.0/include -IOpenMS-1.7.0/contrib/include -I/Library/Frameworks/QtCore.framework/Headers -arch i386 scratch.cpp
It comes up with a boatload of errors (about ~500Kb of them, actually). The problem seems to lie in "using namespace OpenMS;" A small sample of the errors:
Undefined symbols:
"OpenMS::DataValue::DataValue(int)", referenced from:
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::handleUserParam_(OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&)in cc7cSzjW.o
"OpenMS::DataValue::DataValue()", referenced from:
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::handleUserParam_(OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&)in cc7cSzjW.o
"OpenMS::SourceFile::operator!=(OpenMS::SourceFile const&) const", referenced from:
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::writeTo(std::basic_ostream<char, std::char_traits<char> >&)in cc7cSzjW.o
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::writeTo(std::basic_ostream<char, std::char_traits<char> >&)in cc7cSzjW.o
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::writeTo(std::basic_ostream<char, std::char_traits<char> >&)in cc7cSzjW.o
...
ld: symbol(s) not found
collect2: ld returned 1 exit status
Does anyone have insight as to what I'm not doing right?
Try compiling it to an object file (-c) and see if the problems still occur. E..g.: Is this a compiling issue or a linking issue?
Also: Should there be a -L flag to search a particular library path? Should there be a -l flag to link in a particular library?