Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Created July 13, 2014 15:29
Show Gist options
  • Select an option

  • Save benwaffle/a2d42ca4b970d9df720c to your computer and use it in GitHub Desktop.

Select an option

Save benwaffle/a2d42ca4b970d9df720c to your computer and use it in GitHub Desktop.
Calling C++ from C
#include <iostream>
extern "C" void func(){
std::cout << "c++ code\n";
}
#include <stdio.h>
extern void func();
int main(){
printf("some c code\n");
func();
}
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