LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cannot compile simple hello world C++ program in Emacs (https://www.linuxquestions.org/questions/linux-newbie-8/cannot-compile-simple-hello-world-c-program-in-emacs-729534/)

Rafael.Pascual 05-30-2009 12:50 PM

cannot compile simple hello world C++ program in Emacs
 
Hi there!
Please help me figure out what's stopping the compiler to complete its task!

1.#include <iostream>
2.using namespace std;
3.
4.int main()
5.{
6. cout << "hello world" << endl;
7. return 0;
9.}

I used Emacs makefile: gcc –o hello –g hello.cpp

After compiling! Please see below error message

cd /c++/hello/
gcc -o hello -g hello.cpp
/cygdrive/c/Users/RAFAEL~1/AppData/Local/Temp/ccArkUXe.o: In function `_ZSt17__verify_groupingPKcjRKSs':
/usr/local/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2445: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/usr/local/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2454: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/usr/local/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2456: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/usr/local/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2459: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/cygdrive/c/Users/RAFAEL~1/AppData/Local/Temp/ccArkUXe.o: In function `main':
/c++/hello/hello.cpp:6: undefined reference to `std::cout'
/c++/hello/hello.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++/hello/hello.cpp:6: 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++/hello/hello.cpp:6: 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> >&))'
/cygdrive/c/Users/RAFAEL~1/AppData/Local/Temp/ccArkUXe.o: In function `_Z41__static_initialization_and_destruction_0ii':
/usr/local/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/c++/3.4.4/iostream:77: undefined reference to `std::ios_base::Init::Init()'
/usr/local/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/c++/3.4.4/iostream:77: undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status

Compilation exited abnormally with code 1 at Sun May 31 01:21:33

------------------end of first trial----------------------------------

I used Emacs makefile: g++ –o hello –g hello.cpp

After compiling! Please see below error message

cd /c++/hello/
g++ -o hello -g hello.cpp
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_throw.o):(.text+0x76): undefined reference to `___w32_sharedptr_unexpected'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_throw.o):(.text+0x84): undefined reference to `___w32_sharedptr_terminate'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_terminate.o):(.text+0xa5): undefined reference to `___w32_sharedptr_terminate'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_terminate.o):(.text+0x122): undefined reference to `___w32_sharedptr_terminate'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_terminate.o):(.text+0x195): undefined reference to `___w32_sharedptr_unexpected'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_terminate.o):(.text+0x1a9): undefined reference to `___w32_sharedptr_terminate'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_terminate.o):(.text+0x1e5): undefined reference to `___w32_sharedptr_terminate'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a(eh_terminate.o):(.text+0x205): undefined reference to `___w32_sharedptr_unexpected'
collect2: ld returned 1 exit status

Compilation exited abnormally with code 1 at Sun May 31 01:27:38

-----------------------end of second trial---------------------

norobro 05-30-2009 01:02 PM

EDIT: Sorry, I just read your post to the first command prompt where you used gcc. I see below that where you also tried g++.


Take a look at this thread: link


All times are GMT -5. The time now is 08:05 AM.