int cpu = 0;
int player = 0;
char * getPoints()
{
using namespace std;
string str = "You: ";
str += player;
str += " CPU: ";
str += cpu;
char c [100];
strcpy(c, str.c_str());
return c;
}
Run Code Online (Sandbox Code Playgroud)
此代码无法编译.代码是错误的还是我的编译器有问题?
我使用的是Microsoft Visual Studio与DarkGDK.
如果是我,有人可以改善吗?
这是输出:
1>------ Build started: Project: Pong, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>c:\users\martijn\documents\visual studio 2008\projects\pong\pong\main.cpp(42) : warning C4172: returning address of local variable or temporary
1>Linking...
1>libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)
1>Debug\Pong.exe : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://c:\Users\Martijn\Documents\Visual Studio 2008\Projects\Pong\Pong\Debug\BuildLog.htm"
1>Pong - 4 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
小智 6
LNK4098错误表示您的构建混合使用DEBUG设置(因此使用libcmtd.lib)编译的代码和使用非DEBUG设置编译的代码(因此使用libcmt.lib).
或者:它可以是使用动态运行时库(msvcrt.lib)将静态运行时库(libcmt.lib)与代码混合的代码.
然后,链接器找到两个不同版本的公共运行时库方法/类,无法确定使用哪个.您不能在一个构建中混合多个运行时库.
在任何一种情况下,这都是解决方案/项目设置问题.当我们尝试与其他人提供的libs/dll链接时,我们碰到了它们,他们用不同的设置构建它们.
/ NODEFAULTLIB参数(在VS链接器选项下可用作"忽略库"或类似命令)允许您强制忽略这些运行时库集中的一个或多个,只留下一个运行时库集.
| 归档时间: |
|
| 查看次数: |
5704 次 |
| 最近记录: |