0

So here is what happened.

I installed eclipse and eclipse-cdt through apt-get command: sudo apt-get install eclipse eclipse-cdt. I launched Eclipse and created a default C++ project (Image 1) and then I have this unresolved symbols std, cout, endl.

I use 64-bit Linux Mint 16, so gcc is installed by default and I don't have to bother to install any additional C++ software.

So the question is why on Earth it has these unresolved references and how can I resolved them?

Other links recommend to include <stdio.h> (link 1), or to search for unresolved references (link 2) -- but neither of them helped/worked.

I assume the problem is that it doesn't see some specific paths to the libraries, but then how can I find those paths and include them by default?

EDIT 1:

If I run g++ -std=c++11 test.cpp in a command-line I get this error:

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

Image 1

Image 2

Community
  • 1
  • 1
Sergey Ivanov
  • 3,719
  • 7
  • 34
  • 59
  • Are you able to compile on the command-line? – Masked Man Dec 23 '14 at 03:55
  • You'll probably need to install the build-essential package. `gcc` is not C++. – Fred Larson Dec 23 '14 at 04:02
  • If I just do `gcc -std=c++11 test.cpp` in command line , I get this: `/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status`. – Sergey Ivanov Dec 23 '14 at 04:04
  • @FredLarson I have the newest version – Sergey Ivanov Dec 23 '14 at 04:06
  • 2
    Use `g++`, not `gcc`. `gcc` doesn't link the C++ libraries by default. – Fred Larson Dec 23 '14 at 04:07
  • @FredLarson the mistakes are the same as before... even if there were not, how can I resolve this without using bash, but using eclipse? – Sergey Ivanov Dec 23 '14 at 04:11
  • I'm not certain you're using the right toolchain. Are you cross compiling for another platform? – Fred Larson Dec 23 '14 at 04:15
  • @FredLarson No, I'm not. I can change it to Linux GCC, but in addition to those unresolved references that I have now, I also have unresolved inclusion for include statements. – Sergey Ivanov Dec 23 '14 at 04:19
  • I still think you need the build-essential package. I don't know about Mint, but Ubuntu doesn't come with C++ by default. – Fred Larson Dec 23 '14 at 04:22
  • Can you successfully run `echo '#include' | g++ -x c++ -o /dev/null -c -`? – Rufflewind Dec 23 '14 at 04:23
  • FredLarson I have build-essential. @Rufflewind Yes, I can run this without mistakes. It does nothing. – Sergey Ivanov Dec 23 '14 at 04:27
  • @SergeyIvanov When you get `undefined reference to main` that means your source code does not have a main function and you are compiling without the `-c` flag. That is normal behavior. – Rufflewind Dec 23 '14 at 04:31
  • @SergeyIvanov When you get missing headers, however, that is not normal. What command did you use to run the compilation? – Rufflewind Dec 23 '14 at 04:32
  • Check out this question, also about compiling on Mint: http://stackoverflow.com/q/19500018/10077 – Fred Larson Dec 23 '14 at 04:33
  • @Rufflewind In eclipse I didn't run the test.cpp: it just highlights these undefined references. In bash I ran `gcc -std=c++11 test.cpp` (or without -std parameter). – Sergey Ivanov Dec 23 '14 at 05:09
  • @SergeyIvanov Don't use `gcc`. Use `g++`. – Rufflewind Dec 23 '14 at 05:10
  • @Rufflewind I tried with g++ -- it's the same. – Sergey Ivanov Dec 23 '14 at 05:12
  • @SergeyIvanov Paste the full error message in your question. – Rufflewind Dec 23 '14 at 05:13
  • @SergeyIvanov Can you try to run this and see if it produces any error? `echo -e '#include\nint main(){}' | g++ -x c++ -o /dev/null -` – Rufflewind Dec 23 '14 at 05:18
  • @FredLarson If I locate `stdio.h` then I get this: `/home/sergey/bin/boost_1_57_0/boost/iostreams/filter/stdio.hpp /usr/include/stdio.h /usr/include/c++/4.8/tr1/stdio.h /usr/include/x86_64-linux-gnu/bits/stdio.h /usr/lib/perl/5.14.2/CORE/nostdio.h /usr/lib/syslinux/com32/include/stdio.h /usr/local/MATLAB/R2014a/help/matlab/ref/h5p.set_fapl_stdio.html /usr/local/MATLAB/R2014a/sys/lcc/include/stdio.h /usr/local/include/boost/iostreams/filter/stdio.hpp ` – Sergey Ivanov Dec 23 '14 at 05:18
  • @Rufflewind No, it doesn't produce anything. – Sergey Ivanov Dec 23 '14 at 05:19
  • 1
    @SergeyIvanov Are you absolutely sure your `test.cpp` contains a `main` function then? Run `grep main test.cpp` just to be sure. – Rufflewind Dec 23 '14 at 05:20
  • @Rufflewind You're right. Looks like I was running command on unsaved version of the file. Your command still doesn't produce any error, though. However, now Eclipse doesn't highlight those unresolved references. How can I run this code within Eclipse? – Sergey Ivanov Dec 23 '14 at 05:27
  • 1
    @SergeyIvanov I don't really know Eclipse, but ... press the Build button? – Rufflewind Dec 23 '14 at 05:31

0 Answers0