Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VS2008 中编译 c 文件的一个细节

0 views
Skip to first unread message

acc

unread,
Nov 5, 2009, 1:25:16 AM11/5/09
to
�� VS2008 �У����½�һ����Ŀ���� �½���Ŀ �Ի����У���ѡ�� ��Ŀ���� Ϊ��Visual
C++ -> ���桱���� ģ�� ��ָ��������Ŀ����������Ŀ���֡�x��������Զ����һ����Ϊ��x���Ľ���������˽��������һ����Ϊ��x������Ŀ��

Ȼ��������Ŀ���������� ��� ����ѡ�� ���룬�� ģ�� ����ѡ�� C++ �ļ�(.cpp)�������ļ��� x.c���ٴ����������½� x.c �IJ�����ȫһ��ֻ��ȡ�� y���⽫���һ��
��Ϊ y.cpp ���ļ����� ���������Դ������ �У������ļ��������� C++ Сͼ�ꡣ

�����ļ�ʹ����ͬ�����ݡ�����������ݣ������ļ������� #if ��֧�������룬��
#else ��֧�������ԣ�
====================
#ifdef __cplusplus
#define X "c++"
#else
#define X "c"
#endif

#include <stdio.h>

int main()
{
printf(X);
}
====================

�ֱ����еĽ��x.c ��� c��y.cpp ��� c++����Ȼͦ���ܣ����Ҳ��ȷ�����ǿ������е��Ť��x.c ����ʵ�ʱ�����Ƿ��ҵ� #else ��֧����Ϊ vs2008 �������� C++ ���򣬱���
���Ѿ������� __cplusplus��

�ڰ�һ�����е��ļ��� c ��Ϊ cpp ���߷�����ʱ���ǵ����±��롣

��������ӱ����dz����������ӵĿ�ʼ����Ҳ�ܿ�����������������̽�����ӵ�����Ҳ�����޸ģ����ս�������ˣ�Ҳ��ûɶ��˵���ˡ��᲻��ȫɾ�����Ա����˿�ͷ�ͽ��ۡ���


0 new messages