Skip to content

Instantly share code, notes, and snippets.

@manphiz
Last active December 26, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manphiz/7195515 to your computer and use it in GitHub Desktop.
Save manphiz/7195515 to your computer and use it in GitHub Desktop.
C++ stdlib compatibility
#include <iostream>
#include <string>
#include "test_a.h"
#include "test_b.h"
int main(int argc, char** argv)
{
std::string str = "main";
std::cout << test_b(test_a(str)) << "\n";
}
CXX=clang++
GNUCXX=g++-4.8
CFLAGS=-g -Wall -fPIC
LIBCXX="-stdlib=libc++"
LIBSTDCXX="-stdlib=libstdc++"
all: test
test: main.o libtest_a.dylib libtest_b.dylib
$(CXX) $(LIBCXX) -o test main.o -L. -ltest_a -ltest_b
main.o: main.cc
$(CXX) $(LIBCXX) $(CFLAGS) -o main.o -c main.cc
libtest_a.dylib: test_a.o
$(CXX) $(LIBCXX) -dynamiclib -o libtest_a.dylib test_a.o
test_a.o: test_a.cc
$(CXX) $(LIBCXX) $(CFLAGS) -o test_a.o -c test_a.cc
libtest_b.dylib: test_b.o
$(GNUCXX) -dynamiclib -o libtest_b.dylib test_b.o
test_b.o: test_b.cc
$(GNUCXX) $(CFLAGS) -o test_b.o -c test_b.cc
.PHONY: clean
clean:
-rm *.o *.dylib test
CXX=clang++
GNUCXX=g++-4.8
CFLAGS=-g -Wall -fPIC
LIBCXX="-stdlib=libc++"
LIBSTDCXX="-stdlib=libstdc++"
all: test
test: main.o libtest_a.dylib libtest_b.dylib
$(CXX) $(LIBCXX) -o test main.o -L. -ltest_a -ltest_b
main.o: main.cc
$(CXX) $(LIBCXX) $(CFLAGS) -o main.o -c main.cc
libtest_a.dylib: test_a.o
$(CXX) $(LIBCXX) -dynamiclib -o libtest_a.dylib test_a.o
test_a.o: test_a.cc
$(CXX) $(LIBCXX) $(CFLAGS) -o test_a.o -c test_a.cc
libtest_b.dylib: test_b.o
$(CXX) $(LIBSTDCXX) -dynamiclib -o libtest_b.dylib test_b.o
test_b.o: test_b.cc
$(CXX) $(LIBSTDCXX) $(CFLAGS) -o test_b.o -c test_b.cc
.PHONY: clean
clean:
-rm *.o *.dylib test
CXX=clang++
GNUCXX=g++-4.8
CFLAGS=-g -Wall -fPIC
LIBCXX="-stdlib=libc++"
LIBSTDCXX="-stdlib=libstdc++"
all: test
test: main.o libtest_a.dylib libtest_b.dylib
$(GNUCXX) -o test main.o -L. -ltest_a -ltest_b
main.o: main.cc
$(GNUCXX) $(CFLAGS) -o main.o -c main.cc
libtest_a.dylib: test_a.o
$(GNUCXX) -dynamiclib -o libtest_a.dylib test_a.o
test_a.o: test_a.cc
$(GNUCXX) $(CFLAGS) -o test_a.o -c test_a.cc
libtest_b.dylib: test_b.o
$(CXX) -dynamiclib $(LIBSTDCXX) -o libtest_b.dylib test_b.o
test_b.o: test_b.cc
$(CXX) $(CFLAGS) $(LIBSTDCXX) -o test_b.o -c test_b.cc
.PHONY: clean
clean:
-rm *.o *.dylib test
#include "test_a.h"
std::string test_a(std::string const& str)
{
return str + "_test_a";
}
#ifndef TEST_A_H_
#define TEST_A_H_
#include <string>
extern std::string test_a(std::string const& str);
#endif
#include "test_b.h"
std::string test_b(std::string const& str)
{
return str + "_test_b";
}
#ifndef TEST_B_H_
#define TEST_B_H_
#include <string>
extern std::string test_b(std::string const& str);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment