clang ++(版本5)和LNK4217警告

Rob*_*bin 18 linker compiler-warnings 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,而且此代码之前没有产生过这个警告.

Jay*_*Phi 31

-Xclang -flto-visibility-public-std添加到编译器选项中.

像这样:

clang++ -Xclang -flto-visibility-public-std -o test.exe test.cpp

编辑:

或者使用clang-cl代替:

clang-cl -o test.exe test.cpp

  • 工作,但为什么?什么是clang-cl以及该选项有什么作用? (16认同)