Linking g++ compiled code against libraries created by clang++

In my Homebrew installation my libraries are compiled with clang, whereas I would like to, for performance reasons, compile my scientific code with gcc. In order to understand this problem better, I have created a minimal test:

// FILE print.cxx
#include <string>
#include <iostream>

void print_message(const std::string& message)
    std::cout << message << std::endl;

// FILE test.cxx
#include <string>

void print_message(const std::string&);

int main()
    std::string message = "Hello World!";
    return 0;

This code I compile with:

clang++ -stdlib=libstdc++ -c print.cxx
g++ test.cxx print.o

The example that I have added works, but is it possible to make it work with libraries that are compiled without the -stdlib=libstdc++ flag and instead use the libc++?

Source: gcc

Leave a Reply