failing to link: ABI conflict between functions IN THE SAME FILE

  abi, c++, c++11, g++

I do not understand how this can happen. In g++ I am getting an error that there is an ABI conflict between two routines defined in the same file, at the same time, under the same ABI directives. For reasons unknown the linker is searching for the C++11 version of a function, in spite of me being very careful to tell it not to use the C++11 version of absolutely anything, in every last call to g++ in my makefile.

Here is the relevant chunk of makefile – using _D_GLIBCXX_USE_CXX11ABI=0 before anything is included. All the other .o files are built the same way.

project: chrome.o critter.o gene.o loc.o mask.o main.o octree.o rng.o save.o test.o utils.o
    g++ -std=c++17 -D_GLIBCXX_USE_CXX11ABI=0 -D_DEFAULT_SOURCE -lstdc++ -lm -Wall -o project chrome.o critter.o gene.o loc.o mask.o main.o octree.o rng.o save.o test.o utils.o

main.o: main.cpp main.h save.h utils.h gene.h chrome.h critter.h
    g++ -std=c++17  -D_GLIBCXX_USE_CXX11ABI=0 -D_DEFAULT_SOURCE -lstdc++ -c -Wall -o main.o main.cpp 

Here is the relevant chunk of source code.

// the makesave method returns a string which is to be written to a savefile.
std::string rundata::makesave() const { // save all data
    std::string parmsave = rparms.save2string();
    std::string genesave = genes.makesave();
    std::string chromesave = chromes.makesave();
    std::string crittersave = critters.makesave();
    return("<rundata> "+ parmsave + genesave + chromesave + crittersave + " </rundata>n");
}


// the saveData method opens and writes the savefile.
void rundata::saveData(){
    FILE *sav = fopen(rparms.savename(), "w");
    if (sav == NULL) {fprintf(stderr, "Error opening save file to write.n"); exit(1);}
    std::string outstr = makesave();
    fwrite(outstr.data(), 1, outstr.size(), sav);
    fclose(sav);
}

And here’s what happens when I run make:

[email protected]:~/src/nevermind$ make
g++ -std=c++17  -D_GLIBCXX_USE_CXX11ABI=0 -D_DEFAULT_SOURCE -lstdc++ -c -Wall -o main.o main.cpp 2>&1 |  head -20
g++ -std=c++17 -D_GLIBCXX_USE_CXX11ABI=0 -D_DEFAULT_SOURCE -lstdc++ -lm -Wall -o nevermind chrome.o critter.o gene.o loc.o mask.o main.o octree.o rng.o save.o test.o utils.o 2>&1 | head -20
/usr/bin/ld: main.o: in function `rundata::saveData()':
main.cpp:(.text+0x2ac): undefined reference to `rundata::makesave[abi:cxx11]()'
collect2: error: ld returned 1 exit status

This isn’t a call for a wrong-version library function caused by failure to use the macro before including libraries: This is a call to a function defined in the same file, compiled at the same time, with the same ABI directive in place. And I have an ABI conflict?!

How is this even possible?

Source: Windows Questions C++

LEAVE A COMMENT