What is /var/tmp//ccz0ct2G.o? - c++

So, I'm running a CPU scheduling smulation code but I came across a few errors while compiling
Undefined first referenced
symbol in file
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /var/tmp//ccz0ct2G.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> >&)) /var/tmp//ccz0ct2G.o
std::cout /var/tmp//ccz0ct2G.o
std::basic_ofstream<char, std::char_traits<char> >::close() /var/tmp//ccz0ct2G.o
std::ios_base::Init::~Init() /var/tmp//ccz0ct2G.o
std::ios_base::Init::Init() /var/tmp//ccz0ct2G.o
std::basic_ios<char, std::char_traits<char> >::operator!() const /var/tmp//ccz0ct2G.o
__gxx_personality_v0 /var/tmp//ccz0ct2G.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*) /var/tmp//ccz0ct2G.o
std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_Ios_Openmode) /var/tmp//ccz0ct2G.o
std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&) /var/tmp//ccz0ct2G.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
I don't understand why I'm getting these errors and what is /var/tmp//ccz0ct2G.o?
Almost all the errors have it.

I don't understand why I'm getting these errors
Your program tries to use something that's part of an external library or a different object file, but you're not passing that to the linker as well.
and what is /var/tmp//ccz0ct2G.o?
A temporary object file, that contains intermediate data that's going to be used in later stages of the compilation process.
Let me guess: You tried to compile with a command that went something like
g++ somesource.cc
You see, compilation consists of several stages:
1. compiling the individual source files (`*.c`, `*.cc` and so on) into *object files* (`*.o`).
2. linking the produced object files together into the actual program or library
When you call the compiler like you did, this is a shorthand that does both operations from a single call. But for the sake of simplicity and also because object files can grow rather large and it can pose a problem to keep them all in memory, the result of compiling the source file is placed into a temporary object file. That's what you have there.

Related

Using LTO causes undefined reference to std::basic_string destructor

Decided to try LTO in my build (CentOS 7, CMake 3.14.3, gcc 8.2.1, -std=c++17):
# this adds "-flto -fno-fat-lto-objects"
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
All projects build fine, with exception of one:
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(operation_context.cpp.o): In function `_GLOBAL__sub_I_operation_context.cpp':
operation_context.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_block_blob.cpp.o): In function `_GLOBAL__sub_I_cloud_block_blob.cpp':
cloud_block_blob.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_container.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_container.cpp':
cloud_blob_container.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_shared.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_shared.cpp':
cloud_blob_shared.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_ostreambuf.cpp.o): In function `_GLOBAL__sub_I_cloud_blob_ostreambuf.cpp':
cloud_blob_ostreambuf.cpp:(.text.startup+0x9c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/user/vcpkg/installed/x64-linux/lib/libazurestorage.a(cloud_blob_client.cpp.o):cloud_blob_client.cpp:(.text.startup+0x9c): more undefined references to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' follow
collect2: error: ld returned 1 exit status
For some mysterious reason libazurestorage.a provided by vcpkg (where it is built without LTO) can't resolve std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (and only that symbol!).
To make it even more interesting -- other projects that use libazurestorage.a build just fine. I've checked linker's cmdline -- they look practically identical (almost same set of libs, almost same order).
Any ideas what could be wrong? Or how to figure out why other projects build fine?

How do I compile googleTestLibrary on QNX 6.5.0?

I want to compile google Test Library on QNX. But I did not success. I tried everything. Can be seen my compilation errors below
Is someone share to libGoogleTest_g.a and libGoogleTest.a file for me ?
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o):
In function `_M_initialize_dispatch<const char* const*>':
/usr/qnx650/target/qnx6/usr/include/c++/4.4.2/ext/new_allocator.h:87: undefined reference to `std::__throw_bad_alloc()'
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o):
In function `operator<< <char, std::char_traits<char>, std::allocator<char> >':
/usr/qnx650/target/qnx6/usr/include/c++/4.4.2/bits/basic_string.h:2506:
undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o):
In function `ValueHolder':
/usr/qnx650/target/qnx6/usr/include/c++/4.4.2/ext/new_allocator.h:87: undefined reference to `std::__throw_bad_alloc()'
D:/ETCT_PROJECTS/CommonLibrary/Test/ETCCommon/Common/QNXUnitTests/../../../../GoogleTestLibrary/lib\libgoogleTest_g.a(gtest-all.o): In function `~DeathTestImpl':
/home/emres/GoogleTest/./src/gtest-death-test.cc:374:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/emres/GoogleTest/./src/gtest-death-test.cc:374:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/emres/GoogleTest/./src/gtest-death-test.cc:374:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
Check this link to fix the compilation problem.
https://code.google.com/p/googletest/issues/detail?id=444
After you fixed the compilation problem, follow the below steps to create your static library files.
Generate gtest-all.o object file for all configurations(DEBUG RELEASE) simply open QNX momentics and right click to gtest-all.cc
Login to QNX, and copy your gtest-all.o files to any directory
enter the directory to where files copied
create static libraries by using ar(archive) command as shown below.
DEBUG : ar -rv libgoogle_test_g.a gtest-all.o
RELEASE : ar -rv libgoogle_test.a gtest-all.o
Copy *.a files from QNX and use new static library in your project

C++ compilation linking error in OS X [duplicate]

I try to compile this cpp code on osx lion but I get an error.
#include <iostream>
using namespace std;
int main (int argc, char *argv[])
{
for(int i = 0; i < 10; i++)
{
cout << "hi";
cout << endl;
}
return 0;
}
To compile:
cc main.cpp
Error:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccBdbc76.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 ccBdbc76.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 ccBdbc76.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 ccBdbc76.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccBdbc76.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccBdbc76.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Normally this sort of failure happens when compiling your C++ code by invoking the C front-end. The gcc you execute understands and compiles the file as C++, but doesn't link it with the C++ libraries. Example:
$ gcc example.cpp
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccLTUBHJ.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 ccLTUBHJ.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 ccLTUBHJ.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 ccLTUBHJ.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccLTUBHJ.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccLTUBHJ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
$ g++ example.cpp
$
As you can see, using g++ makes the problems go away. The same behaviour (with slightly different messages) occurs if you use clang (which I'd recommend):
$ clang example.cpp
Undefined symbols for architecture x86_64:
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in cc-IeV9O1.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in cc-IeV9O1.o
"std::cout", referenced from:
_main in cc-IeV9O1.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 cc-IeV9O1.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 cc-IeV9O1.o
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
_main in cc-IeV9O1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ clang++ example.cpp
$
As you can see in the clang error message, you could use -v to see the linker invocation to see what's going wrong. It would show you this link line:
"/usr/bin/ld" -demangle -dynamic -arch x86_64
-macosx_version_min 10.6.8 -o a.out -lcrt1.10.6.o
/var/folders/zl/zlZcj24WHvenScwjPFFFQE+++TI/-Tmp-/cc-hdOL8Z.o
-lSystem /Developer/usr/bin/../lib/clang/3.0/lib/darwin/libclang_rt.osx.a
Or something like it - as you can see, it's linking the C runtime, not C++, and also doesn't have the C++ libraries. Using clang++ the link line is:
"/usr/bin/ld" -demangle -dynamic -arch x86_64
-macosx_version_min 10.6.8 -o a.out -lcrt1.10.6.o
/var/folders/zl/zlZcj24WHvenScwjPFFFQE+++TI/-Tmp-/cc-wJwxjP.o
/usr/lib/libstdc++.6.dylib -lSystem
/Developer/usr/bin/../lib/clang/3.0/lib/darwin/libclang_rt.osx.a
As you can see, libstdc++ is included, and presto - no link errors.
Try
g++ main.cpp
This way it should work, at least using OS X
I'm not familiar with OSX LION. However, in the strictest sense, the errors described are not caused by the compiler, but by the linker. It seems as if the standard library is not being linked.
Use CC command (uppercase) to compile C++ and link to standard C++ library.
As of Yosemite (10.10.1), I've found that gcc with the -lc++ flag also works:
gcc -lc++ main.cpp
If using clang on OS X , try :
clang++ simple_cpp_program_file.cpp -o simple_cpp_program_file.out
Here's the solution that works on macOs Sierra:
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.
Is this GCC on Windows (MinGW) or Linux? On MinGW you need the parameters -lmingw32 -enable-auto-import. Linux might needs something similar, -enable-auto-import is most likely needed.
So the error ld: library not found for -lstdc++ is where the actual error lies.
To fix this, open the folder
open /Library/Developer/CommandLineTools/Packages/
Run the package macOS_SDK_headers_for_macOS_10.14.pkg
Then gem install mini_racer works!
This issue may not be only related to mini_racer as it could affect any gem that compiles an extension.。

clang mac link errors with gtest Undefined symbols for architecture x86_64

Not sure what issue I am having here.
Mac clang 3.1 cmake
gtest
few files
using few C++11 features
I have downloaded and installed XCode build tools
CMAKE_CXX_FLAGS = -Wall -std=c++0x -stdlib=libc++ -v
builds fine with output...
[100%] Building CXX object CMakeFiles/soupbintcptest.dir/soupmessages_tests.cpp.o
clang version 3.1 (tags/RELEASE_31/final)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
Linking dumps a slew of errors. ABI errors? I know there is this C++11 namespace mangling thing happening.
Undefined symbols for architecture x86_64:
They are all things in the std:: namespace that will not link like:
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::_Setprecision)", referenced from:
testing::AssertionResult testing::internal::FloatingPointLE<float>(char const*, char const*, float, float) in libgtest.a(gtest-all.cc.o)
testing::AssertionResult testing::internal::FloatingPointLE<double>(char const*, char const*, double, double) in libgtest.a(gtest-all.cc.o)
testing::Message::Message() in libgtest.a(gtest-all.cc.o)
or
"std::cerr", referenced from:
testing::internal::GTestLog::GetStream() in libgtest.a(gtest-all.cc.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
testing::UnitTest::AddTestPartResult(testing::TestPartResult::Type, char const*, int, testing::internal::String const&, testing::internal::String const&) in libgtest.a(gtest-all.cc.o)
testing::internal::SingleFailureChecker::~SingleFailureChecker() in libgtest.a(gtest-all.cc.o)
testing::internal::StringStreamToString(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*) in libgtest.a(gtest-all.cc.o)
testing::TestInfo::TestInfo(char const*, char const*, char const*, char const*, void const*, testing::internal::TestFactoryBase*) in libgtest.a(gtest-all.cc.o)
testing::TestInfo::~TestInfo() in libgtest.a(gtest-all.cc.o)
testing::internal::ReportInvalidTestCaseType(char const*, char const*, int) in libgtest.a(gtest-all.cc.o)
testing::internal::XmlUnitTestResultPrinter::PrintXmlUnitTest(__sFILE*, testing::UnitTest const&) in libgtest.a(gtest-all.cc.o)
...
I believe I have built gtest with the same clang++ version. Not sure what else is going on here to drive these issues.
I've seen similar errors to yours when the linker is pulling in a different c++ library to the one that matches what the compiler is building for. In your case, you are only modifying the compiler flags, but the linker doesn't know your choice and is likely linking to the wrong C++ library.
If you are able to use CMake 3.2 or later, then rather than modifying the C++ compiler flags directly, I'd recommend you just tell CMake you want to use C++11 and then let it work out the appropriate compiler and linker flags for you. This can be done by adding the following before your project() call:
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
This and related CMake features are discussed in detail in this article.
There is nothing C++11 about name mangling, it's been going on since the very first C++ implementations. However, do not forget that you must have built gtest for the same stdlib switch, because it can't find the Standard libraries.

Runtime c++ "undefined symbol" exception

I am getting an undefined symbol exception for a method that is actually executing. This makes no sense to me. Here is an example of the log:
/src/CustomerReturnProcessUtils/labelPrintUtils/CreturnLabelPrinter.cpp:402 (null)(): CreturnLabelPrinter: [InitializeZebraPrint] Success connecting to socket
/apollo/env/CustomerReturnUIServiceUS/bin/CustomerReturnUIService: symbol lookup error: /apollo/env/CustomerReturnUIServiceUS/bin/CustomerReturnUIService: undefined symbol: _ZN19CreturnLabelPrinter10PrintLabelESsSsiiiSsbSs
The "Success connecting to socket" is logged by a method call INSIDE of CreturnLabelPrinter::PrintLabel...how can I be getting an undefined symbol exception for that? This is a non-static method. The code for it is not relevant (and I can't post it here anyways)...I am just wondering what conditions this could happen under. I haven't seen any problems during the compiling and linking of these modules. The calling method is in a different library than the "undefined symbol".
Thi happened to me when I had 2 versions of the library and I was linking against the wrong one. Also c++filt shows:
$ c++filt __ZN19CreturnLabelPrinter10PrintLabelESsSsiiiSsbSs
CreturnLabelPrinter::PrintLabel(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
This has a huge list of arguments, did you check them?