Created
July 13, 2014 15:29
-
-
Save benwaffle/a2d42ca4b970d9df720c 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" void func(){ | |
| std::cout << "c++ code\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
| #include <stdio.h> | |
| extern void func(); | |
| int main(){ | |
| printf("some c code\n"); | |
| func(); | |
| } |
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
| cpp: | |
| g++ -shared -fPIC -o libcppcode.so cppcode.cpp | |
| c: | |
| gcc -L. -lcppcode -o main main.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment