请教编译选项TP的含义

arkuka 2007-07-09 10:51:16
TP到底是什么含义,看MSDN上说:/TC and /TP are global variants of /Tc and /Tp. They specify to the compiler to treat all files named on the command line as C source files (/TC) or C++ source files (/TP), without regard to location on the command line in relation to the option。
这里的all files named on the command line是什么意思,我看我们的commandline里面没有什么文件名啊,如果没有文件名那是不是就会作用于所有的C/C++文件啊。
下面是我们的commandline
/O2 /Ob1 /I "..\dirlib" /I "..\..\..\transcoder\reslib" /I "..\..\..\transcoder\common_lib" /D "WIN32" /D "NDEBUG" /D "MEMFILEIO" /D "_VC80_UPGRADE=0x0710" /D "_WINDLL" /D "_AFXDLL" /D "_ATL_STATIC_REGISTRY" /D "_MBCS" /FD /EHa /MD /Zc:wchar_t- /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /clr:oldSyntax /TP /errorReport:prompt
我们的commandline里面没有任何文件名,那是不是意味着所有的C文件还是用C编译器编译,所有的C++文件还是用C++编译器编译。
我的理解正确吗?
还望高手指正。
...全文
444 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
arkuka 2007-07-10
  • 打赏
  • 举报
回复
经过我的测试发现,因为我的工程的命令行中没有列出任何文件,所以,C文件会被C编译器编译,C++文件会被C++编译器编译。
这只是根据实验结果得到的结论,哪位大师有不同意见,还望指正。
arkuka 2007-07-10
  • 打赏
  • 举报
回复
又做了一个测试,貌似TP,TC会影响所有源文件,不管是否列在command line中,个人猜测cl应该和gnu的makefile类似,根据某些隐含规则project中的所有源文件都应该算是在command line中,只是没有显式的写出来而已.
taianmonkey 2007-07-10
  • 打赏
  • 举报
回复
/Tc, /Tp, /TC, /TP (Specify Source File Type)See Also
Compiler Options | Setting Compiler Options
/Tcfilename
/Tpfilename
/TC
/TP
where:

filename
A C or C++ source file.
Remarks
The /Tc option specifies that filename is a C source file, even if it doesn't have a .c extension. The /Tp option specifies that filename is a C++ source file, even if it doesn't have a .cpp or .cxx extension. A space between the option and filename is optional. Each option specifies one file; to specify additional files, repeat the option.

/TC and /TP are "global" variants of /Tc and /Tp. They specify to the compiler to treat all files named on the command line as C source files (/TC) or C++ source files (/TP), without regard to location on the command line in relation to the option. These global options can be overridden on a single file via /Tc or /Tp.

By default, CL assumes that files with the .c extension are C source files and files with the .cpp or the .cxx extension are C++ source files.

To set this compiler option in the Visual Studio development environment

Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the C/C++ folder.
Click the Advanced property page.
Modify the Compile As property.
To set this compiler option programmatically

See CompileAs Property.

Examples
The following CL command line specifies that MAIN.c, TEST.prg, and COLLATE.prg are all C source files. CL will not recognize PRINT.prg.

CL MAIN.C /TcTEST.PRG /TcCOLLATE.PRG PRINT.PRG
The following CL command line specifies that TEST1.c, TEST2.cxx, TEST3.huh, and TEST4.o are compiled as C++ files, and TEST5.z is compiled as a C file.

CL TEST1.C TEST2.CXX TEST3.HUH TEST4.O /Tc TEST5.Z /TP
arkuka 2007-07-09
  • 打赏
  • 举报
回复
麻烦各位大师仔细看看我的问题。最好能帮我指出我们的命令行里说明那些C文件会被当作C++文件处理。另外treat as c++,是不是意味着对应的文件的编译结果中的函数、变量会被按照C++的方式修饰。多谢多谢!
DentistryDoctor 2007-07-09
  • 打赏
  • 举报
回复
/TP 是/Tp 的全局变量。它指定编译器将在命令行上命名的所有文件视为 C++ 源文件,而不考虑它们在命令行上相对于选项的位置。
DentistryDoctor 2007-07-09
  • 打赏
  • 举报
回复
/Tp 选项指定 filename 为 C++ 源文件,即使它没有 .cpp 或 .cxx 扩展名
菜牛 2007-07-09
  • 打赏
  • 举报
回复
/Tc 选项指定 filename 为 C 源文件,即使它没有 .c 扩展名。/Tp 选项指定 filename 为 C++ 源文件,即使它没有 .cpp 或 .cxx 扩展名。选项和 filename 之间的空格可选。每个选项指定一个文件;若要指定其他文件,请重复此选项。

/TC 和 /TP 是 /Tc 和 /Tp 的“全局”变形。它们指定编译器将在命令行上指定的所有文件视为 C 源文件 (/TC) 或 C++ 源文件 (/TP),而不考虑它们在命令行上相对于选项的位置。这些全局选项可以在单个文件上通过 /Tc 或 /Tp 重写。

默认情况下,CL 假定扩展名为 .c 的文件是 C 源文件,扩展名为 .cpp 或 .cxx 的文件是 C++ 源文件。

示例
下列 CL 命令行指定 MAIN.c、TEST.prg 和 COLLATE.prg 都是 C 源文件。CL 将不识别 PRINT.prg。
CL MAIN.C /TcTEST.PRG /TcCOLLATE.PRG PRINT.PRG
下列 CL 命令行指定 TEST1.c、TEST2.cxx、TEST3.huh 和 TEST4.o 作为 C++ 文件编译,TEST5.z 作为 C 文件编译。
CL TEST1.C TEST2.CXX TEST3.HUH TEST4.O /Tc TEST5.Z /TP

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧