Last active
December 26, 2015 18:38
-
-
Save manphiz/7195515 to your computer and use it in GitHub Desktop.
C++ stdlib compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "test_a.h" | |
std::string test_a(std::string const& str) | |
{ | |
return str + "_test_a"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TEST_A_H_ | |
#define TEST_A_H_ | |
#include <string> | |
extern std::string test_a(std::string const& str); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "test_b.h" | |
std::string test_b(std::string const& str) | |
{ | |
return str + "_test_b"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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