C/C++ mixed programming 본문

Programming/C++

C/C++ mixed programming

halatha 2011. 5. 25. 00:45
2011/05/24 - [Programming/C++] - C/C++ mixed programming
2011/05/24 - [Programming/C++] - C/C++ mixed programming
출처: http://yesarang.tistory.com/66
이미 존재하는 C library를 C++에서 사용하는 경우

//	max.h
int max(int a, int b);

//	cppmain.cpp
#include 
extern "C" {
#include "max.h"
}

using namespace std;

int main(void)
{
	int	im	=	max(100, 30);

	cout << "int max = " << im << endl;
}

/*
$ gcc -c max.c
$ g++ -c cppmain.cpp 
$ g++ -o cppmax cppmain.o max.o 
$ ./cppmax 
int max = 100
*/
Comments