The following call from the command line, clang++ vcfaltcount.cpp -o vcfac, produces the following error/warnings
>In file included from vcfaltcount.cpp:1:
./Variant.h:86:5: warning: control may reach end of non-void function [-Wreturn-type]
}
>Undefined symbols for architecture x86_64:
"split(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in ccGOdUhH.o
vcf::VariantCallFile::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccGOdUhH.o
"vcf::VariantCallFile::getNextVariant(vcf::Variant&)", referenced from:
_main in ccGOdUhH.o
"vcf::VariantCallFile::parseHeader()", referenced from:
vcf::VariantCallFile::openFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccGOdUhH.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
There are many other posts on "undefined symbols for such&such architecture," and I have attempted to use those suggestions to successfully compile.
I think the problem may arise from the header file, variant.h. In the API from which the source code came there was a corresponding variant.cpp file that defined the functions, which were only declared in variant.h. I moved those definitions into variant.h. Any thoughts on what I may be missing? I can provide the header if need be, but it is long. Thanks.
Related
so I've been trying to install OpenCV with C++ on my mac using this tutorial: https://medium.com/#jaskaranvirdi/setting-up-opencv-and-c-development-environment-in-xcode-b6027728003 but I keep getting this error on Xcode:
" 'opencv2/core.hpp' file not found "
I tried setting both Library Search Paths and Header Search Paths to recursive but it didn't change anything
I've also been getting this error on the terminal, I don't know if it's related. I think it's important to note that this isn't my first time trying to install opencv and I don't know if it's the old versions that keep messing with it. I tried to cleanup everything before installing this version but I'm not sure.
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in main-55ed98.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main-55ed98.o
cv::String::operator=(cv::String const&) in main-55ed98.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in main-55ed98.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in main-55ed98.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestions on how to solve these issues please?
After upgrading to Mac OS X 10.9 / Xcode 5.0.1, command lines to create a shared library (.dylib) failed with several undefined symbols.
clang++ -dynamiclib -install_name test.dylib *.o -o test.dylib
Undefined symbols for architecture x86_64:
"std::allocator<char>::allocator()", referenced from:
_main in test.o
"std::allocator<char>::~allocator()", referenced from:
_main in test.o
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
_main in test.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
_main in test.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
_main in test.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test.o
"std::cout", referenced from:
_main in test.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 test.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in test.o
ld: symbol(s) not found for architecture x86_64
The answer is there: https://mathematica.stackexchange.com/questions/34692/mathlink-linking-error-after-os-x-10-9-mavericks-upgrade
There are two implementations of the standard C++ library available on OS X: libstdc++ and libc++. They are not binary compatible and libMLi3 requires libstdc++.
On 10.8 and earlier libstdc++ is chosen by default, on 10.9 libc++ is chosen by default. To ensure compatibility with libMLi3, we need to choose libstdc++ manually.
To do this, add -stdlib=libstdc++ to the linking command.
Related post: Compiling with Clang using Libc++ undefined references
Edit: After some investigations it seems there is a link between the -mmacosx-version-min and the choice of the default libstd. If min version < 10.9, then the default libstd is equal to libstdc++, else to libc++. The long term solution is clearly to use -stdlib=libc++
Those suggestions did not work for me with Mac El capitan. If you have similar issues after upgrading to El Capitan, just run
xcode-select --install
before trying to compile
I am trying to use a template class and when I compile it in one file in LWS it works:
(Link is dead)
~http://liveworkspace.org/code/a9c412a7e683439dfa35a9363749369d~
But when I try to compile it made-up of 3 files,
stack.h lines 4 to 21
stack.cpp lines 24 to 48
main.cpp lines 49 to end
When I try to compile those 3 files I get
Undefined symbols for architecture x86_64:
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::push(Node**, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in ccCoizCT.o
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::top(Node*&)", referenced from:
_main in ccCoizCT.o
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::pop(Node*&)", referenced from:
_main in ccCoizCT.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Yes I have included stack.h in a stack.cpp and main.cpp files
Sounds like you need to place the template definitions of stack back in the header file. Templates form a plan for code generation, so if the compiler can't see the entire template definition and only sees the declaration, code for that specific instantiations of the template will not be generated. It will simply trust the declaration and expect that at link time there exists an objects file with the instantiations of those templates. The solution to this is 1) keep the template definitions in the header file or 2) pre-generate the required definitions so the linker can find them at link time.
See here:
Template issue causes linker error (C++)
I'm using OS X 10.7.3. I've been playing with the boost headers for a while now and i wanted to move onto using the Boost.Filesystem lib however it keeps throwing this message at me:
Undefined symbols for architecture x86_64:
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccOhIhNG.o
boost::filesystem3::detail::create_directories(boost::filesystem3::path const&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::canonical(boost::filesystem3::path const&, boost::filesystem3::path const&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccOhIhNG.o
(anonymous namespace)::error(bool, boost::system::error_code const&, boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
(anonymous namespace)::error(bool, boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
(anonymous namespace)::error(bool, boost::filesystem3::path const&, boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::dir_itr_close(void*&, void*&)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_itera tor&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::directory_iterator_construct(boost::filesystem3::directory_itera tor&, boost::filesystem3::path const&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
i get this when i try to compile using this:
g++ -o test main.cpp -I -l/opt/local/include ~/boost/libs/libboost_filesystem.a
So i went back to the boost.org tutorials and tried out the regex example. It worked perfectly using this:
g++ -o test main.cpp -I -l/opt/local/include ~/boost/libs/libboost_regex.a
try
g++ -o test main.cpp -I/opt/local/include -L/opt/local/lib -lboost_filesystem
Your compiler flags seem a bit off. Generally, the following hold:
-I // Sets the path for the relevant header files
-L // Sets the path where your libraries reside
-l // specifies the library you want to link against.
So, if you have a library called mylib in ~/libs/ and need to use header files located in ~/include, you'd pass
-I ~/include -L ~/libs -lmylib
as flags to the compiler.
Xcode is giving me the following error, I don't really know what to do, is driving my crazy.
I'm importing an OpenCV framework so maybe the problem is there or something related to the compiler.
Could anyone tell me what to do or search for?
Undefined symbols: "_CGImageDestinationCreateWithURL", referenced from:
cv::ImageIOEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)in OpenCV(grfmt_imageio.o) "_CGImageDestinationAddImage", referenced from:
cv::ImageIOEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)in OpenCV(grfmt_imageio.o) "_CGImageSourceCreateImageAtIndex", referenced from:
cv::ImageIODecoder::readHeader() in OpenCV(grfmt_imageio.o) "_CGImageDestinationFinalize", referenced from:
cv::ImageIOEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)in OpenCV(grfmt_imageio.o) "_CGImageSourceCreateWithURL", referenced from:
cv::ImageIODecoder::readHeader() in OpenCV(grfmt_imageio.o) ld: symbol(s) not found collect2: ld returned 1 exit status
Just for sake of future visitors (like me ;-)), I report the Gustavo self-answer:
Add
"ImageIO.framework"
to
"Linked Frameworks and Library"