我可能做错了什么,做个新手.你能帮帮我吗?
我在C中编写了一个名为hello.c的简单Hello World程序,并运行以下命令:
gcc -S hello.c
Run Code Online (Sandbox Code Playgroud)
那产生了hello.s.然后我用GNU汇编程序使用该文件as:
as hello.s
Run Code Online (Sandbox Code Playgroud)
哪个产生了非可执行文件a.out,哪些仍然需要链接,我明白了吗?
我尝试通过使用链接它ld,如下所示:
ld a.out
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
a.out: file not recognized: File truncated
Run Code Online (Sandbox Code Playgroud)
并ld删除我的文件.
这是一个x86 Ubuntu系统.我究竟做错了什么?非常感谢!
我正试图从Deitel的书中做另一个练习.该程序计算每月利息并打印每个储户的新余额.由于练习是与动态内存相关的章节的一部分,我使用的是"new"和"delete"运算符.出于某种原因,我得到了这两个错误:
LNK2019:函数___tmainCRTStartup中引用的未解析的外部符号WinMain @ 16
致命错误LNK1120:1个未解析的外部因素
这是类头文件.
//SavingsAccount.h
//Header file for class SavingsAccount
class SavingsAccount
{
public:
static double annualInterestRate;
SavingsAccount(double amount=0);//default constructor intialize
//to 0 if no argument
double getBalance() const;//returns pointer to current balance
double calculateMonthlyInterest();
static void modifyInterestRate(double interestRate):
~SavingsAccount();//destructor
private:
double *savingsBalance;
};
Run Code Online (Sandbox Code Playgroud)
具有成员函数定义的Cpp文件
//SavingsAccount class defintion
#include "SavingsAccount.h"
double SavingsAccount::annualInterestRate=0;//define and intialize static data
//member at file scope
SavingsAccount::SavingsAccount(double amount)
:savingsBalance(new double(amount))//intialize savingsBalance to point to new object
{//empty body
}//end of constructor
double SavingsAccount::getBalance()const
{ …Run Code Online (Sandbox Code Playgroud) 我收到了以下错误,并且不能为我的生活弄清楚我做错了什么.
$ gcc main.c -o main
Undefined symbols:
"_wtf", referenced from:
_main in ccu2Qr2V.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
main.c中:
#include <stdio.h>
#include "wtf.h"
main(){
wtf();
}
Run Code Online (Sandbox Code Playgroud)
wtf.h:
void wtf();
Run Code Online (Sandbox Code Playgroud)
wtf.c:
void wtf(){
printf("I never see the light of day.");
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我将整个函数包含在头文件中而不仅仅是签名中,那么它就符合要求,因此我知道wtf.h被包含在内.为什么编译器看不到wtf.c?或者我错过了什么?
问候.
我有一个庞大而复杂的项目,最终得到了单元测试.我已经在Visual Studio 2010本地构建了googleTest 1.6.0,使用cmake构建的项目文件就像README指定的那样.
该项目有许多静态和动态链接的依赖库.其中许多是专有的.所有链接尝试都会产生220个这样的错误.这是一个抽样:
msvcprtd.lib(MSVCP100D.dll):错误LNK2005:"public:void __cdecl std :: _ Container_base12 :: _ Orphan_all(void)"(?_ Olphan_all @ _Container_base12 @std @@ QEAAXXZ)已在gtest.lib中定义(gtest-all. OBJ)
libcpmtd.lib(cerr.obj):错误LNK2005:"protected:char*__cdecl std :: basic_streambuf> :: _ Gndec(void)"(?_ Gndec @?$ basic_streambuf @ DU?$ char_traits @ D @ std @@@ std @@ IEAAPEADXZ)已在msvcprtd.lib中定义(MSVCP100D.dll)
LIBCMTD.lib(setlocal.obj):错误LNK2005:已在MSVCRTD.lib中定义_configthreadlocale(MSVCR100D.dll)
链接:警告LNK4098:defaultlib'MSVCRTD'与使用其他库冲突; use/NODEFAULTLIB:library LINK:警告LNK4098:defaultlib'LIBCMTD'与使用其他库冲突; 使用/ NODEFAULTLIB:库
致命错误LNK1169:找到一个或多个多重定义的符号
我已经尝试了/ NODEFAULTLIB标志,并且我试图忽略msvcprtd.lib,MSVCRTD.lib和LIBCMTD.lib,如建议的那样,但后来我遇到了未解决的符号......
项目和googleTest都使用x64,/ MP,/ MDd和no/clr进行编译.
我一直在玩编译器标志,想知道是否存在某种版本不匹配.在我理解的范围内,Dumpbin没有暗示我可能理解的任何东西.我希望有一个呃
我正在尝试在Linux上构建Clang(亚马逊的EC2).我按照指南运行make:
http://clang.llvm.org/get_started.html
我收到以下链接错误消息:
llvm[2]: Linking Debug+Asserts executable opt
/home/ec2-user/benchmark/build/tools/opt/Debug+Asserts/opt.o: In function `llvm::ParseIR(llvm::MemoryBuffer*, llvm::SMDiagnostic&, llvm::LLVMContext&)':
opt.cpp:(.text._ZN4llvm7ParseIREPNS_12MemoryBufferERNS_12SMDiagnosticERNS_11LLVMContextE[llvm::Pars eIR(llvm::MemoryBuffer*, llvm::SMDiagnostic&, llvm::LLVMContext&)]+0x5f): undefined reference to `llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
collect2: ld returned 1 exit status
make[2]: *** [/home/ec2-user/benchmark/build/Debug+Asserts/bin/opt] Error 1
make[2]: Leaving directory `/home/ec2-user/benchmark/build/tools/opt'
make[1]: *** [opt/.makeall] Error 2
make[1]: Leaving directory `/home/ec2-user/benchmark/build/tools'
make: *** [all] Error 1
Run Code Online (Sandbox Code Playgroud)
有谁知道这意味着什么?
编辑:我从svn重建了整个项目,现在我收到以下错误:
COMPILE: clang_linux/asan-i386/i386: /home/ec2-user/benchmark/llvm/projects/compiler-rt/lib/asan/asan_rtl.cc
/home/ec2-user/benchmark/llvm/projects/compiler-rt/lib/asan/asan_rtl.cc:28:10: fatal error: 'new' file not found
#include <new>
^
1 error generated.
make[5]: *** [/home/ec2-user/benchmark/build/tools/clang/runtime/compiler-rt/clang_linux/asan-i386/i386/SubDir.lib__asan/asan_rtl.o] Error 1
make[5]: …Run Code Online (Sandbox Code Playgroud) 自从我开始使用它以来,我对Winsock只有麻烦.我似乎无法初始化Winsock来拯救我的生命.我不是要求任何人编写整个程序(因为我知道这有多烦人)我只需要帮助Winsock.我已经尝试了几个编译器,总是会遇到奇怪的错误.
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main
1>C:\Users\Rory\ProjectX\ProjectX\Debug\ProjectX.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\Rory\ProjectX\ProjectX\ProjectX\Debug\BuildLog.htm"
1>ProjectX - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <winsock2.h>
int iReqWinsockVer = 2;
using namespace std;
int main()
{
cout<<"Initializing Winsock …Run Code Online (Sandbox Code Playgroud) One Definition Rule规定程序应包含每个非内联函数的一个定义.对于模板类的成员,这对我来说并不完全清楚:
///////////
// Tfoo.h
template<typename T> class A {
void foo(){}
};
///////////
// intfoo.h
#include <Tfoo.h>
template<> class Foo<int> {
void foo(); // declaration only
};
/*inline*/ void Foo<int>::foo(){} // definition
///////////
// X.cpp
#include <intfoo.h>
///////////
// Y.cpp
#include <intfoo.h>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,clientX.obj和clientY.obj都有一个定义Foo<int>::foo.链接器抱怨此符号定义不止一次:
Y.obj : error LNK2005: "private: void __thiscall Foo<int>::foo(void)"
(?foo@?$Foo@H@@AAEXXZ) already defined in X.obj
Run Code Online (Sandbox Code Playgroud)
当我在前面inline定义时Foo<int>::foo(),一切顺利,链接器很高兴.当我在单独的编译单元中定义它们时(例如intfoo.cpp).
(注意:此解决方案在/sf/answers/103725751/中提出)
可能是一种误解,但模板类的成员函数总是"内联"?这里的规则是什么?
c++ templates linker-errors one-definition-rule explicit-specialization
简单的问题:
给出以下程序:
#include <stdio.h>
inline void addEmUp(int a, int b, int * result)
{
if (result) {
*result = a+b;
}
}
int main(int argc, const char * argv[])
{
int i;
addEmUp(1, 2, &i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到链接器错误...
Undefined symbols for architecture x86_64:
_addEmUp", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
看起来似乎没有费心去编译它.
它不应该是static,我不会想,基于我读过的内容:
链接器错误内联函数(因为这是在一个不同的对象,并处理2个定义而不是零)
这是一个相关的链接,但它是c ++,我认为在std C中将代码放入头文件中是不错的做法: …
在链接期间,我收到以下消息:
LINK : fatal error LNK1101: incorrect MSPDB120.DLL version; recheck installation of this product
我在VC2013的早期版本中看到了类似错误的解决方案,但这些错误对我来说并不适用.其中包括:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat我第一次遇到这个错误时,我继续完全重新安装VC2013.我选择了这次溃败,因为我想也许我在安装VC2013之后通过安装旧版本的VC搞砸了安装.虽然重新安装第一次工作,但我不建议这样做.MS安装程序似乎相当破碎,并在重复尝试时挂断了我,导致我的生命损失超过5小时.
如果前两个选项不起作用,有什么其他解决方案可以解决这个问题?
我建立了一些的Visual C++ DLL和EXE项目与Visual Studio 2012年当默认的平台工具集建筑V110构建成功,但与Windows XP兼容的平台工具集构建时v110_xp失败,并在每个项目下面的链接器错误:
链接:致命错误LNK1104:无法打开文件',5.01'
需要注意的是,如果我改变从平台的Win32到x64时错误更改为:
链接:致命错误LNK1104:无法打开文件',5.02'
通过在Visual Studio中的"空项目"模板中创建一个新的EXE项目并添加一些*.cpp文件定义,可以轻松地重现这一点int main() {return 6;}.它将成功构建,直到您将平台工具集从v110更改为v110_xp.
为什么会发生这种情况?如何在Windows XP兼容性下成功构建这些项目?
linker-errors ×10
c ×3
c++ ×3
build ×2
visual-c++ ×2
clang ×1
dll ×1
googletest ×1
inline ×1
lnk2005 ×1
lnk2019 ×1
makefile ×1
templates ×1
winsock ×1