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?
Related
I'm trying to use Openmp on my mac, but i'm getting a compiler error I don't understand. I installed openmp using
brew install llvm
When I try to compile my code using -fopenmp I get errors like this
Undefined symbols for architecture x86_64:
"std::runtime_error::what() const", referenced from:
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> > in ccOEbbPM.o
vtable for boost::exception_detail::error_info_injector<std::runtime_error> in ccOEbbPM.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::range_error> > in ccOEbbPM.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::overflow_error> > in ccOEbbPM.o
vtable for boost::exception_detail::error_info_injector<std::range_error> in ccOEbbPM.o
vtable for boost::exception_detail::error_info_injector<std::overflow_error> in ccOEbbPM.o
"std::locale::operator==(std::locale const&) const", referenced from:
boost::detail::lcast_put_unsigned<std::char_traits<char>, unsigned long long, char>::convert() in ccOEbbPM.o
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_not_of(char, unsigned long) const", referenced from:
boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >::do_get_string[abi:cxx11](std::_Ios_Fmtflags, mpl_::bool_<false> const&) const in ccOEbbPM.o
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
std::basic_ostream<char, std::char_traits<char> >& boost::multiprecision::operator<< <boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >, (boost::multiprecision::expression_template_option)1>(std::basic_ostream<char, std::char_traits<char> >&, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >, (boost::multiprecision::expression_template_option)1> const&) in ccOEbbPM.o
It's just a small segment of the error code since it goes on for quite a while, but I post the rest if need be. I also have the boost library installed.
Any help is appreciated, thanks.
EDIT:
Simple program that causes the error:
#include <iostream>
#include <omp.h>
using namespace std;
int main(){
int x = 5;
#pragma omp parallel
for(int y = 0; y < 50;y++){
x += 5;
}
cout << x << endl;
return 0;
}
Commands used to compile:
gcc-7 -fopenmp -Wall ex.cc
gcc-7 -std=c++11 -fopenmp -Wall ex.cc (I get less errors doing it this way)
Error when using the second compile command:
Undefined symbols for architecture x86_64:
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in ccXt8Pa8.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in ccXt8Pa8.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccXt8Pa8.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccXt8Pa8.o
"std::cout", referenced from:
_main in ccXt8Pa8.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in ccXt8Pa8.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Use g++-7 rather than gcc-7, and all will be fine - it is C++ after all ;-)
g++-7 -std=c++11 -fopenmp openmp.cpp -o openmp
i am trying to build webrtc version 62 , using the following
1.git checkout -b branch62 refs/remotes/branch-heads/62
2.gn gen out_release_62/x64/Debug --args="rtc_include_tests=false rtc_use_h264=false use_rtti=true is_component_build=false enable_iterator_debugging=false enable_nacl=false target_os=\"linux\" target_cpu=\"x64\" is_debug=true"
3.ninja -C out_release_62/x64/Debug
i am linking to libwebrtc.a and libwebrtc_common.a
but wherever i try to use RTC_CHECK_EQ or RTC_DCHECK_LT i get the the following error
undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
and
out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':
i had no issue with build branch head 60 ,
i tried linking to librtc_base.a and librtc_base_approved.a but no luck.
A sample program that produces this error is
#include <iostream>
#include <string>
#include <webrtc/rtc_base/checks.h>
#include <webrtc/rtc_base/ssladapter.h>
#include <webrtc/rtc_base/logging.h>
#include <webrtc/api/peerconnectioninterface.h>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
std::string type;
std::string sdp;
webrtc::SdpParseError error;
webrtc::CreateSessionDescription(type,sdp,&error);
RTC_DCHECK(5);
RTC_CHECK_EQ(1,6);
RTC_DCHECK_LT(1,4);
return 0;
}
gcc verison 6.3 linker
g++ -L/home/test/webrtc-checkout-ankur/src/out_release_62/x64/Debug -o "testwebrtc" ./src/testwebrtc.o -lwebrtc -lwebrtc_common -lpthread -lm -ldl
this is the error that is returned
./src/testwebrtc.o: In function `main':
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:22: undefined reference to `webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:24: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:25: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
./src/testwebrtc.o: In function `rtc::CheckEqImpl(int, int, char const*)':
makefile:45: recipe for target 'testwebrtc' failed
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:179: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
collect2: error: ld returned 1 exit status
From my observation any function/method that has std::string in it is showing this behaviour.
_GLIBCXX_USE_CXX11_ABI=0 has been set, and -std=c++0x , this build is done on an ubuntu 16.04 system.
running nm on the built library i get
find -iname '.a' -exec nm -A -C {} \; | grep 'T rtc::FatalMessage::FatalMessage('
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
and
find -iname '.a' -exec nm -A -C {} \; | grep 'CreateSessionDescription('
./Debug/obj/webrtc/pc/libpeerconnection.a:jsepsessiondescription.o:0000000000000000 T webrtc::CreateSessionDescription(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&, webrtc::SdpParseError*)
./Debug/obj/webrtc/libwebrtc.a:jsepsessiondescription.o:0000000000000000 T webrtc::CreateSessionDescription(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&, webrtc::SdpParseError*)
please help
you have a standard lib mismatch: on one hand you use std::string, on the other hand you use std::__1::basic_string
in other words: on one hand you use libc++ on the other hand you use libstdc++
You need to use clang and pass
-stdlib=libstdc++
to the compiler command line.
__1 signifies that we are using the libc++ llvm-clang library, which is the default for webrtc builds
__1 is the inlined namespace that libc++ uses,
so as to solve this particular issue, we should either use libc++ instead of libstdc++ in our application when we link to libwebrtc,
or
build webrtc to use libstdc++,
to let gn know that we intend to use libstdc++, we pass use_custom_libcxx=false and use_custom_libcxx_for_host=false as args
I started learning C++ and I tried to run the classic Hello World program:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello, World!";
return 0;
}
but when I compile it in terminal using GCC I always get that error:
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccpe3DPY.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const", referenced from:
std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccpe3DPY.o
"std::cout", referenced from:
_main in ccpe3DPY.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccpe3DPY.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccpe3DPY.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccpe3DPY.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in ccpe3DPY.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
can you tell me why?
You've compiled your program with gcc, which is a C compiler, not a C++ compiler. Use g++ instead; it knows to include the C++ run-time libraries, where those missing symbols are defined.
Thats a C compiler you need to use a C++ compiler like rob says above g++. Also if you are a beginner I would highly recommend using Microsoft visual studio express if you run a windows OS; if not then netbeans.
Ok, I just switched to MacOS after a while of Windows/Linux coexistence. I open a simple text editor, write a simple program just to check if everything is all right. I know there are other threads about this error but it just seems that in all the other cases the problem lied in a specific part of their program, which in turn is far more complex than this. I just want to understand why the compiler says what it says even with a simple thing like this.
#include <iostream>
#include "numeri.h"
int main(void)
{
std::cout << numeri() << std::endl;
return 0;
}
with
//numeri.h
int numeri(void);
and
//numeri.cpp
#include "numeri.h"
int numeri(void)
{
return (3);
}
what I get from gcc helloworld.cpp -Wall is
Undefined symbols for architecture x86_64:
"numeri()", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in cc6WY2MJ.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cc6WY2MJ.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in cc6WY2MJ.o
"std::cout", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in cc6WY2MJ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
2 cases:
1 - I forgot how to use a simple header (I prefix, I'm a physics student, I can program for what it regards physics and numeric simulations [or at least, I could], but I just don't know that much about linkers-compilers-architecture and this kind of stuff)
2 - something's wrong
The C++ compiler is g++, . Also you need to add numeri.cpp to your commmand line.
g++ helloworld.cpp numeri.cpp -Wall
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 :-)