我错误地使用了这个在链接步骤失败的命令:
$ clang -std=c++11 -stdlib=libc++ myInputFile.cpp
任何人都可以解释为什么clang提供了C++语言选项,以及为什么它无法链接?为什么不选择-x c++或-std=c++11完成同样的事情clang++?谢谢!
我只是在学习如何编码.
我使用visual studio 14在Windows 10系统上安装了clang版本5.
我创建了一个hello world cpp文件来测试它是否正常工作.
示例代码
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
int rip{1};
int dal{4};
int kane = rip + dal;
cout << kane;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
命令
clang++ -o .\bin\testing.exe test.cpp
Run Code Online (Sandbox Code Playgroud)
Clang确实编译了,我得到一个可执行文件,它按预期运行.但我确实收到了这条消息.
test-3e53b3.o : warning LNK4217: locally defined symbol ___std_terminate imported in function "int `public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)'::`1'::dtor$5" (?dtor$5@?0???1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ@4HA)
test-3e53b3.o : warning LNK4217: locally defined symbol __CxxThrowException@8 imported in function "public: void __thiscall std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QAEXH_N@Z)
Run Code Online (Sandbox Code Playgroud)
我在网上搜索过,可以找到类似的问题,但它们不一样.
我意识到这对你们来说可能很简单,但我不知道我使用过各种IDES和GCC,而且此代码之前没有产生过这个警告.
我在链接步骤上有警告.这些警告仅在发布模式下出现.
我的程序由两部分组成:一个生成.lib的库和一个使用该库的可执行文件.
当我建立图书馆时,我没有任何警告.但是当我构建我的可执行文件时,在链接上我发出警告LNK4217和LNK4049.例如:
3>DaemonCommon.lib(Exception.obj) : warning LNK4217: locally defined symbol ??0exception@std@@QAE@ABQBD@Z (public: __thiscall std::exception::exception(char const * const &)) imported in function "public: __thiscall std::bad_alloc::bad_alloc(char const *)" (??0bad_alloc@std@@QAE@PBD@Z)
3>DaemonCommon.lib(CommAnetoException.obj) : warning LNK4217: locally defined symbol ??0exception@std@@QAE@ABQBD@Z (public: __thiscall std::exception::exception(char const * const &)) imported in function "public: __thiscall std::bad_alloc::bad_alloc(char const *)" (??0bad_alloc@std@@QAE@PBD@Z)
Run Code Online (Sandbox Code Playgroud)
我在MSDN中读过,这些警告可能是由__declspec(dllimport)的声明引起的.但是,在我的lib类中,我没有像这样声明的东西.例如,这是我的类Exception:
#ifndef _EXCEPTION_HPP__
#define _EXCEPTION_HPP__
#include <string>
namespace Exception
{
class Exception
{
public:
// Constructor by default
Exception();
// Constructor parametrized
Exception(std::string& strMessage);
// Get the message of …Run Code Online (Sandbox Code Playgroud) 我有来自http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe的 clang 3.9
clang version 3.9.0 (branches/release_39)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
Run Code Online (Sandbox Code Playgroud)
和gcc 6.2.0(Mingw-w64)
gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
我的PC上没有安装MSVC,也没有安装Windows SDK.我需要clang的一些特殊功能,我想用gcc替换它,更具体地说用g ++替换它因为我使用C++.
当我尝试编译简单文件时,我得到:
致命错误:找不到'string'文件
这是否意味着我目前的clang安装不支持windows上的mingw?基本上我只想使用mingw-w64安装中的头文件和库.我一直在寻找解决方案而没有找到任何东西.我不知道该怎么办.
这是否也意味着我的clang安装取决于我没有的MSVC?
编辑: 从本页面的评论:http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/
这不再适用于LLVM的最新二进制文件(3.7.1,3.8,3.9),因为它们是使用Visual Studio和Visual Studio编译的.
您可以安装完整的Visual Studio 2015(大约8GB)或安装"Microsoft Visual C++ Build Tools 2015 Update …