Skip to content

Instantly share code, notes, and snippets.

@aprell
Last active January 28, 2016 20:35
Show Gist options
  • Select an option

  • Save aprell/2bf9e49271864d2585c5 to your computer and use it in GitHub Desktop.

Select an option

Save aprell/2bf9e49271864d2585c5 to your computer and use it in GitHub Desktop.
Calling C from C++
#include <iostream>
extern "C" int sum(int, int);
int main()
{
std::cout << sum(1, 2) << "\n";
}
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
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