Last active
January 28, 2016 20:35
-
-
Save aprell/2bf9e49271864d2585c5 to your computer and use it in GitHub Desktop.
Calling C from C++
This file contains hidden or 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> | |
| extern "C" int sum(int, int); | |
| int main() | |
| { | |
| std::cout << sum(1, 2) << "\n"; | |
| } |
This file contains hidden or 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
| CC = clang | |
| CFLAGS = -Wall -Wextra | |
| CXX = clang++ | |
| CXXFLAGS = $(CFLAGS) -std=c++11 | |
| extern_C: extern_C.o sum.o | |
| $(CXX) $(CXXFLAGS) $^ -o $@ | |
| clean: | |
| rm -f extern_C extern_C.o sum.o | |
| .PHONY: clean |
This file contains hidden or 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
| int sum(int a, int b) | |
| { | |
| return a + b; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment