0

I'm using Eclipse and have been including the relevant libraries in the project folder as I build. Now that I'm a bit further in the course, I'm trying to

#include "vector.h"

but building gives 16 warnings that look like:

In file included from ../CS106B_Prog_Ass01_05.cpp:6: Finished building: ../CS106B_Prog_Ass01_05.cpp ../vector.h:560:26: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]

and the following error that prevents the project from building:

Undefined symbols for architecture x86_64: "mainWrapper(int, char**)", referenced from: _main in CS106B_Prog_Ass01_05.o "__mainFlags", referenced from: _main in CS106B_Prog_Ass01_05.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [CS106B_Prog_Ass01_05] Error 1

I would love to simply link to the library folder, but that results in a similar error even if I switch it to a different architecture. Has anyone had this problem?

bigbrass
  • 1
  • 2
  • You may need to enable C++11. What version of eclipse? – user4581301 Apr 06 '16 at 23:09
  • Version: Helios Service Release 2 Build id: 20110218-0911 – bigbrass Apr 06 '16 at 23:59
  • Jinkies. That's a hoary beast. The C++ constructs may give the CODAN module fits, so you might have to turn off some of the helper pre-compilation warnings and analysis. but you should be able to open up the build options and add `-std=c++11` for the miscellaneous build arguments to make the compiler happy. Unfortunately I can't remember where that was in Helios. Fortunately this dude seems to: http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support/22001437#22001437 – user4581301 Apr 07 '16 at 00:09
  • Looks like it's a pretty old version. I installed the following: Version: Mars.2 Release (4.5.2) Build id: 20160218-0600 And am still running into the same problem. – bigbrass Apr 07 '16 at 00:11
  • I stumbled across that answer, but the trouble is the path he's describing isn't what I see in Eclipse. Once I get to Settings, there is no 'Discovery' tab as he describes. . . – bigbrass Apr 07 '16 at 00:15
  • Most of that is useless to you. Doesn't exist. But `Properties/C/C++ Build->Settings->Tool Settings->GCC C++ Compiler->Miscellaneous->Other Flags` sounds right. Add in `-std=c++11`. – user4581301 Apr 07 '16 at 00:22
  • Getting the compiler to work in mars is easy: `Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Compiler->Dialect` Use the drop-down to select C++11 – user4581301 Apr 07 '16 at 00:24
  • I have tried both these suggestions, and am getting the same error. Will return shortly, with scotch. – bigbrass Apr 07 '16 at 00:25
  • Crap. Wasn't paying enough attention to the error message. This is clang. This any help? http://stackoverflow.com/questions/7875241/activating-c11-support-in-clang – user4581301 Apr 07 '16 at 00:29
  • I will take a closer look in a moment, but I am on a Mac. – bigbrass Apr 07 '16 at 00:30
  • Here's the full error message I'm getting: make all Building target: CS106B_Prog_Ass01_05 Invoking: MacOS X C++ Linker g++ -o "CS106B_Prog_Ass01_05" ./CS106B_Prog_Ass01_05.o Undefined symbols for architecture x86_64: "getLine(std::__1::basic_string, std::__1::allocator >)", referenced from: _main in CS106B_Prog_Ass01_05.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [CS106B_Prog_Ass01_05] Error 1 – bigbrass Apr 07 '16 at 01:01
  • Looks like you've gotten around the C++11 problem then. This error looks like it can't find a `getLine` that takes a `string`. Different problem. You have a function prototype that looks something like `getLine(std::string)` but either no implementation of the function, the implementation and the prototype do not match, or the implementation is in another C++ file that is not being built or linked. – user4581301 Apr 07 '16 at 01:16
  • That means that the configuration I'm using to link it to the stanfordcpplib folder on my desktop isn't working, which doesn't make any sense. The code that I'm using perfectly recognizes a vector.h file found in the folder on my desktop. – bigbrass Apr 07 '16 at 01:35
  • Check that the contents of vector.h aren't header-only. If vector.h is implemented entirely in the header it doesn't need to be separately compiled and linked in. You likely have a header that contains the prototype, the instructions for calling a function, but the function is in a cpp file that needs to be compiled and linked or has been compiled and is inside a library that needs to be linked. This conversation is kind of sprawling. I think you might need to open up a new question. – user4581301 Apr 07 '16 at 01:46

0 Answers0