0

EDIT: I run nm -C unit.o | grep ergebnis as suggested in the comments and got the following output:

0000000000001210 T ergebnis(std::vector<Student, std::allocator<Student> > const&)
0000000000000350 T ergebnis(std::vector<double, std::allocator<double> > const&)
0000000000000810 T ergebnis(std::vector<std::string, std::allocator<std::string> > const&)

so the overload should exist and is correct, right?


I have a file unit.o given, it's header looks like:

#ifndef unit2b
#define unit2b

#include "student.h"
#include <iostream>
#include <vector>
#include <string>


// Funktionen zur Ueberpruefung der Ergebnisse
// geben zurueck, ob ein Fehler entdeckt wurde
bool ergebnis( const std::vector<double>& feld);
bool ergebnis( const std::vector<std::string>& feld);
bool ergebnis( const std::vector<Student>& feld);

#endif

In my program (sort.cpp) i have three vector's, one of type double, one of type Student, and one of type std::string. I am calling some sort algorithms, and ergebnis(x) for each of that vectors after that. trying to compile with

clang++ -std=c++14 -o prog sort.cpp unit.o student.cpp

i get the following error:

/tmp/sort-cc51a6.o: In function `main':
sort.cpp:(.text+0x548): undefined reference to `ergebnis(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

i am very new to c++ and don't understand what the problem could be. The interesting part is, that the error only occurs for the ergebnis() call with the std::string type vector - the other two types work fine. The calls in sort.cpp:

std::ifstream ifs1 ("strings.txt", std::ifstream::in);
std::vector<std::string> v1 = {};
einlesen(ifs1, v1);
[...]
if(!(ergebnis(v1)){ ... }

what could the problem be?

EDIT: this is not a duplicate. I read the other question, and tried everything that was suggested in the accepted answer. The problem is also, that i have no access to the source code which unit.o was created of. so please remove the duplicate mark.

T_01
  • 1,256
  • 3
  • 16
  • 35
  • You're missing a definition of the `ergebnis( const std::vector& feld)` overload of the function. – Barmar May 04 '18 at 00:41
  • Try running the file `unit.o` through the [`nm`](https://sourceware.org/binutils/docs/binutils/nm.html) command and see if the symbol for that function is present: `nm -C unit.o | grep ergebnis`. You should see symbols for each overload. – Paul Belanger May 04 '18 at 00:41
  • @Barmar the problem is, i have no access to the source code unit.cpp i have only the unit.o file – T_01 May 04 '18 at 00:43
  • @PaulB okay i try it. one moment.. – T_01 May 04 '18 at 00:43
  • should'nt it be nm -C++ ? – T_01 May 04 '18 at 00:44
  • The header file claims that this overload exists, but it seems like it's wrong. – Barmar May 04 '18 at 00:45
  • i edited my questionat the top – T_01 May 04 '18 at 00:46
  • `unit.o` was compiled with libstdc++4, and you compile with the C++11 ABI from stdlibc++ 5+. You can't mix those. Compile against libstdc++4 ABI. – Baum mit Augen May 04 '18 at 00:47
  • how can i set this? -std=libstdc+4 ? what is ABI? – T_01 May 04 '18 at 00:49
  • this are homeworks.. the last time we got also files compiled in that version and i did the exact same thing, and it worked.. – T_01 May 04 '18 at 00:49
  • *"what is ABI"* Now that's not hard to google. For instructions, see the dupe. – Baum mit Augen May 04 '18 at 00:50
  • oh of course sorry, i can google it. and you can remove the duplicate mark, because it obviously isn't. – T_01 May 04 '18 at 00:51
  • i tried defining _GLIBCXX_USE_CXX11_ABI 0 and now get an Segmentation fault (core dumped) – T_01 May 04 '18 at 00:54
  • compiling with -stdlib=libc++ i get "iostream" file not found error.... – T_01 May 04 '18 at 00:56
  • That's a different bug in your code probably, or more incompatibility issues with your mystical `unit.o`. Everything from here is crystal ball debugging unless you figure out how that file was compiled. – Baum mit Augen May 04 '18 at 00:58
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170328/discussion-between-t-01-and-baum-mit-augen). – T_01 May 04 '18 at 00:58

0 Answers0