0

我有想用 Visual Studio 2010 构建的 C 源代码。它引用了两个库,我认为我已将它们正确添加到我的项目中,请参见图像。

据我了解,我应该将源文件重命名为 name.c 以便编译为 C。当我构建我的解决方案时,我在 AssemblyInfo.cpp 上得到一个未定义的命名空间错误。

我该如何解决这些错误?

请注意,我还有一个 .OBJ、.LIB 和 .MAK 文件与该程序一起使用。打开 .MAK 文件时,出现以下错误:

编辑:

我将该项目重新创建为 Win32 控制台项目。编译解决方案时出现以下错误:

1>------ Build started: Project: SerialCommWin32, Configuration: Debug Win32 ------
1>  SerialCommWin32.cpp
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\asynch_1.h(44): error C2143: syntax error : missing ',' before '*'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\asynch_1.h(73): error C2143: syntax error : missing ',' before '*'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(272): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(272): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(272): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(272): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(272): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(447): error C2664: 'wrtst_a1' : cannot convert parameter 4 from 'uint *' to 'int *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(454): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(454): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(454): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(454): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(454): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(464): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(464): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(464): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(464): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(464): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(464): error C2143: syntax error : missing ';' before '{'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(491): error C2664: 'wrtst_a1' : cannot convert parameter 4 from 'uint *' to 'int *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(498): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(498): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(498): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(498): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(498): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(508): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(508): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(508): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(508): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(508): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(508): error C2143: syntax error : missing ';' before '{'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(532): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(546): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(585): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(710): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(728): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(746): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(765): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(779): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(779): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(779): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(779): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(779): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(782): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(782): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(782): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(782): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(782): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(946): warning C4309: '=' : truncation of constant value
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1364): error C2664: 'rdst_a1' : cannot convert parameter 3 from 'uchar *' to 'char *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1393): error C2146: syntax error : missing ')' before identifier 'far'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1393): error C2065: 'far' : undeclared identifier
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1393): warning C4197: 'volatile long' : top-level volatile in cast is ignored
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1393): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1393): error C2059: syntax error : ')'
1>c:\users\jgoddijn\documents\development\vanduijnen\serialcommwin32\serialcommwin32\serialcommwin32.cpp(1393): error C2143: syntax error : missing ';' before '{'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
4

1 回答 1

2

编译器可能并不真正关心文件扩展名。您可以查看项目的设置:C/C++ -> Advanced -> Compile As然后选择C Code(尽管有效的 C 代码也应该是有效的 C++ 代码)。

此外,AssemblyInfo.cpp它仅适用于 C++/CLI 项目。因此,删除该文件或将其从构建中排除。

看起来将项目创建为 C++/CLI 项目,因此您可能需要编辑更多项目设置,或者(最好的解决方案 IMO)将项目文件重新创建为本机 C/C++ 项目(如Win32 项目Win32 控制台应用)。

于 2012-10-17T13:44:33.760 回答