I'm using draco and boost together. Draco is working well after this question.
I have tried to install boost and i think its done.
Now i try to run this command in vs-code on wsl :
g++ -I ~/local/include -L ~/local/lib -o prog ObjContainer.cpp -ldracodec -lboost_system
errors:
ObjContainer.cpp:(.text._ZN5boost7archive6detail15common_iarchiveINS0_15binary_iarchiveEED2Ev[_ZN5boost7archive6detail15common_iarchiveINS0_15binary_iarchiveEED5Ev]+0x22): undefined reference to `boost::archive::detail::basic_iarchive::~basic_iarchive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char, std::char_traits<char> >::~binary_iarchive_impl()':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEED2Ev[_ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEED5Ev]+0x32): undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::~basic_binary_iprimitive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::char_traits<char> >::binary_oarchive_impl(std::ostream&, unsigned int)':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC2ERSoj[_ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC5ERSoj]+0x55): undefined reference to `boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::char_traits<char> >::basic_binary_oprimitive(std::basic_streambuf<char, std::char_traits<char> >&, bool)'
ObjContainer.cpp:(.text._ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC2ERSoj[_ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC5ERSoj]+0xab): undefined reference to `boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::char_traits<char> >::~basic_binary_oprimitive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char, std::char_traits<char> >::binary_iarchive_impl(std::istream&, unsigned int)':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC2ERSij[_ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC5ERSij]+0x55): undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::basic_binary_iprimitive(std::basic_streambuf<char, std::char_traits<char> >&, bool)'
ObjContainer.cpp:(.text._ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC2ERSij[_ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC5ERSij]+0xab): undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::~basic_binary_iprimitive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::char_traits<char> >::init(unsigned int)':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEE4initEj[_ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEE4initEj]+0x21): undefined reference to `boost::archive::basic_binary_oarchive<boost::archive::binary_oarchive>::init()'
The boost::archive class is part of Boost.Serialization library.
You need to link with -lboost_serialization -lboost_system at the end.
Related
This question already has answers here:
What is the difference between g++ and gcc?
(10 answers)
Closed last year.
I am exploring vscode. when i am building file with gcc then is is throwing error while with g++ it is successfull.can anyone explain the reason.below is with g++
Starting build...
C:\MinGW\bin\g++.exe -fdiagnostics-color=always -g "C:\Users\Nikhil Kumar\VS Project\DSA_Practice\kadane.cpp" -o "C:\Users\Nikhil Kumar\VS Project\DSA_Practice\kadane.exe"
Build finished successfully...while below is with gcc
Starting build...
C:/MinGW/bin/gcc.exe -fdiagnostics-color=always -g "C:\Users\Nikhil Kumar\VS Project\DSA_Practice\kadane.cpp" -o "C:\Users\Nikhil Kumar\VS Project\DSA_Practice\kadane.exe"
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\NIKHIL~1\AppData\Local\Temp\ccsbjjAr.o: in function main': C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:6: undefined reference to std::cout'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:6: undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:7: undefined reference to std::cin'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:7: undefined reference to std::istream::operator>>(int&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:9: undefined reference to std::cout'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:9: undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:11: undefined reference to std::cin'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:11: undefined reference to std::istream::operator>>(int&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:22: undefined reference to std::cout'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:22: undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:22: undefined reference to std::ostream::operator<<(int)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:22: undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Nikhil Kumar/VS Project/DSA_Practice/kadane.cpp:22: undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\NIKHIL~1\AppData\Local\Temp\ccsbjjAr.o: in function _tcf_0': c:/mingw/lib/gcc/mingw32/9.2.0/include/c++/iostream:74: undefined reference to std::ios_base::Init::~Init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\NIKHIL~1\AppData\Local\Temp\ccsbjjAr.o: in function _static_initialization_and_destruction_0': c:/mingw/lib/gcc/mingw32/9.2.0/include/c++/iostream:74: undefined reference to std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status
Build finished with error(s).
can anyone explain what's going on?
gcc is not the c compiler, it is "gnu compiler collection". As this, calling gcc with a cpp file will call internally the g++ to compile the file. But as a result you get a *.o file. And now you link all the stuff with the gcc-c-compiler. This is possible at all, but it did not link to the c++stdlib.so/a file. If you link with gcc you need to manually add c++stdlib. But it is highly recommended to use g++ for compile AND link!
OK.
It's been a while since I wrote any C++.
And I'm rusty.
So what am I doing wrong here, and why?
#include <iostream>
std::string hello() {
return "another green world";
}
int main(int argc, char **argv) {
std::cout << hello() << std::endl;
return 0;
}
Then compiling with :
gcc test.cpp -o test
gives me
/tmp/ccxCCo47.o: In function `hello[abi:cxx11]()':
test.cpp:(.text+0x34): undefined reference to `std::allocator<char>::allocator()'
test.cpp:(.text+0x4b): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
test.cpp:(.text+0x57): undefined reference to `std::allocator<char>::~allocator()'
test.cpp:(.text+0x7b): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccxCCo47.o: In function `main':
test.cpp:(.text+0xcb): undefined reference to `std::cout'
test.cpp:(.text+0xd0): undefined reference to `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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test.cpp:(.text+0xda): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
test.cpp:(.text+0xe5): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
test.cpp:(.text+0xf1): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test.cpp:(.text+0x116): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccxCCo47.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x156): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x16b): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccxCCo47.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
You need to include your header file.
#include <iostream>
Also, try compiling with g++ instead of gcc.
g++ test.cpp
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Error "undefined reference to 'std::cout'"
(6 answers)
Closed 6 years ago.
So I was trying out the Linux C++ compiler and this happened while compiling the following code:
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World!\n"<<endl;
return 0;
}
ceibal#ceibal:~$ gcc HelloWorld.cpp
/tmp/cc78Dkhk.o: In function `main':
HelloWorld.cpp:(.text+0xa): undefined reference to `std::cout'
HelloWorld.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
HelloWorld.cpp:(.text+0x1c): undefined reference to `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> >&))'
/tmp/cc78Dkhk.o: In function `__static_initialization_and_destruction_0(int, int)':
HelloWorld.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld devolvió el estado de salida 1
ceibal#ceibal:~$ pico HelloWorld.cpp
ceibal#ceibal:~$ gcc HelloWorld.cpp
HelloWorld.cpp:3:1: error: expected ‘;’ before ‘int’
ceibal#ceibal:~$ pico HelloWorld.cpp
ceibal#ceibal:~$ gcc HelloWorld.cpp
/tmp/ccIivRal.o: In function `main':
HelloWorld.cpp:(.text+0xa): undefined reference to `std::cout'
HelloWorld.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
HelloWorld.cpp:(.text+0x1c): undefined reference to `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> >&))'
/tmp/ccIivRal.o: In function `__static_initialization_and_destruction_0(int, int)':
HelloWorld.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld devolvió el estado de salida 1
I tried with the same program but on C and it worked perfectly, but as soon as I translated it to c++ this occurred.
$ gcc HelloWorld.cpp
This invokes C compiler but your code is in C++. Use g++ to invoke C++ compiler.
$ g++ HelloWorld.cpp
So I have a vector of arrays of pointers to floats. I am trying to push back an array of null pointers of type float*. When I do, I get an error which I will post at the end. Here is teh code:
#include <iostream>
#include <math.h>
#include <vector>
#include <tr1/array>
using namespace std;
typedef vector< tr1::array<float* , 2> > polygon;
void triangle_solver(float*,float*,float*,float*,float*,float*);//Prototype function for solving triangles, 6 floats for 3 sides and 3 angles
void polygon_solver(polygon poly);
void displayPoly(polygon);
int main()
{
polygon test;
cout << test.size() << endl;
//polygon_solver(test);
return 0;
}
void displayPoly(polygon poly)
{
for (polygon::iterator it = poly.begin(); it != poly.end(); it++)
{
for (int c=0; c<2; c++)
{
if ((*it)[c]) cout << *(*it)[c] << endl;
else cout << '?' << endl;
}
}
}
void polygon_solver(polygon poly)
{
if (poly.size() > 3)
{
float *a1 = NULL;
float *a3 = NULL;
float *s2 = NULL;
polygon sub(poly.begin()+2, poly.end()-1);
float *A1 = NULL;
float *A3 = NULL;
float *S2 = NULL;
sub.push_back({A1, S2}); //ERROR HERE
float *aA3 = poly[2][1];
float *aA1 = poly[0][1];
cout << "Sub Polygon: " << endl;
displayPoly(sub); cout << endl;
for (int c=0; c<1; c++)
{
triangle_solver(a1, poly[1][1], a3, poly[1][0], s2, poly[0][1]);
polygon_solver(sub);
}
cout << "Polygon: " << endl;
displayPoly(poly); cout << endl;
}
}
I am using NULL to represent unknowns (is this standard?) Note that it compiles in code blocks but does not run, and also will not compile by running gcc at the command line. Here is the error:
main.cpp: In function ‘void polygon_solver(polygon)’:
main.cpp:45:23: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
sub.push_back({A1, S2});
^
main.cpp:45:31: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
sub.push_back({A1, S2});
^
/tmp/ccZsz9el.o: In function `main':
main.cpp:(.text+0x25): undefined reference to `std::cout'
main.cpp:(.text+0x2a): undefined reference to `std::ostream::operator<<(unsigned long)'
main.cpp:(.text+0x2f): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x37): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccZsz9el.o: In function `displayPoly(std::vector<std::tr1::array<float*, 2ul>, std::allocator<std::tr1::array<float*, 2ul> > >)':
main.cpp:(.text+0xf4): undefined reference to `std::cout'
main.cpp:(.text+0xf9): undefined reference to `std::ostream::operator<<(float)'
main.cpp:(.text+0xfe): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x106): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
main.cpp:(.text+0x112): undefined reference to `std::cout'
main.cpp:(.text+0x117): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)'
main.cpp:(.text+0x11c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x124): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccZsz9el.o: In function `polygon_solver(std::vector<std::tr1::array<float*, 2ul>, std::allocator<std::tr1::array<float*, 2ul> > >)':
main.cpp:(.text+0x2f5): undefined reference to `std::cout'
main.cpp:(.text+0x2fa): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.cpp:(.text+0x2ff): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x307): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
main.cpp:(.text+0x343): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x348): undefined reference to `std::cout'
main.cpp:(.text+0x34d): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
main.cpp:(.text+0x431): undefined reference to `std::cout'
main.cpp:(.text+0x436): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.cpp:(.text+0x43b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x443): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
main.cpp:(.text+0x476): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x47b): undefined reference to `std::cout'
main.cpp:(.text+0x480): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccZsz9el.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x555): undefined reference to `std::ios_base::Init::Init()'
main.cpp:(.text+0x564): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccZsz9el.o: In function `std::vector<std::tr1::array<float*, 2ul>, std::allocator<std::tr1::array<float*, 2ul> > >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::tr1::array<float*, 2ul>*, std::vector<std::tr1::array<float*, 2ul>, std::allocator<std::tr1::array<float*, 2ul> > > >, std::tr1::array<float*, 2ul> const&)':
main.cpp:(.text._ZNSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_[_ZNSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_]+0x271): undefined reference to `__cxa_end_catch'
main.cpp:(.text._ZNSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_[_ZNSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_]+0x284): undefined reference to `__cxa_begin_catch'
main.cpp:(.text._ZNSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_[_ZNSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_]+0x2ec): undefined reference to `__cxa_rethrow'
/tmp/ccZsz9el.o: In function `std::vector<std::tr1::array<float*, 2ul>, std::allocator<std::tr1::array<float*, 2ul> > >::_M_check_len(unsigned long, char const*) const':
main.cpp:(.text._ZNKSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE12_M_check_lenEmPKc[_ZNKSt6vectorINSt3tr15arrayIPfLm2EEESaIS3_EE12_M_check_lenEmPKc]+0x4c): undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccZsz9el.o: In function `__gnu_cxx::new_allocator<std::tr1::array<float*, 2ul> >::deallocate(std::tr1::array<float*, 2ul>*, unsigned long)':
main.cpp:(.text._ZN9__gnu_cxx13new_allocatorINSt3tr15arrayIPfLm2EEEE10deallocateEPS4_m[_ZN9__gnu_cxx13new_allocatorINSt3tr15arrayIPfLm2EEEE10deallocateEPS4_m]+0x1c): undefined reference to `operator delete(void*)'
/tmp/ccZsz9el.o: In function `__gnu_cxx::new_allocator<std::tr1::array<float*, 2ul> >::allocate(unsigned long, void const*)':
main.cpp:(.text._ZN9__gnu_cxx13new_allocatorINSt3tr15arrayIPfLm2EEEE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorINSt3tr15arrayIPfLm2EEEE8allocateEmPKv]+0x2c): undefined reference to `std::__throw_bad_alloc()'
main.cpp:(.text._ZN9__gnu_cxx13new_allocatorINSt3tr15arrayIPfLm2EEEE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorINSt3tr15arrayIPfLm2EEEE8allocateEmPKv]+0x3c): undefined reference to `operator new(unsigned long)'
/tmp/ccZsz9el.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
Your error log points out a warning, and a linkage error.
1) Your 2 first warnings says that your are using c++11 features, while not specifying to compile with c++11 standart. Warnings does not stop the compilation, unless you use the -Werror flag. But you should still fix them by adding -std=c++11 in your compilation line.
2) Your linkage error simply tells you that linker couldn't find std::cout. That is because gcc does not link correctly the C++'s std library. Add this flag : -lstdc++, or use g++ instead (source : Compiling a C++ program with gcc)
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
string a;
cin>>a;
float v=strtof(a.c_str(),NULL);
cout<<v;
}
The above code works in g++ compiler. But in gcc its reporting following error.
/tmp/ccz60ueB.o: In function `main':
test1.cpp:(.text+0x12): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
test1.cpp:(.text+0x21): undefined reference to `std::cin'
test1.cpp:(.text+0x26): undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
test1.cpp:(.text+0x32): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'
test1.cpp:(.text+0x55): undefined reference to `std::cout'
test1.cpp:(.text+0x5a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(float)'
test1.cpp:(.text+0x66): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test1.cpp:(.text+0x81): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccz60ueB.o: In function `__static_initialization_and_destruction_0(int, int)':
test1.cpp:(.text+0xac): undefined reference to `std::ios_base::Init::Init()'
test1.cpp:(.text+0xb1): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccz60ueB.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
You have to use g++ (or any C++ compiler) so it links with the C++ version of the library std. You shouldn't try to compile C++ code with a C compiler.
The following example works just fine for g++.
std::string asd="12312332434";
float as;
istringstream a;
a.str(asd);
a>>as;
cout<<as;
The following example must work fine for gcc.
//#include <stdio.h>
//#include <stdlib.h>
char asd[10];
float i;
fgets ( asd, 10, stdin );
i = atoi (asd);
gcc detects the language based on the file extension, so it can compile C++. However, you need to tell it to link against libstdc++.
For example:
gcc -o test test.cc -lstdc++
However, I'm not sure why you would do this.