21

I am just learning how to code.

I have installed clang version 5 on a windows 10 system using visual studio 14.

I created a hello world cpp file to test that is working.

Sample code

#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;
}

command

clang++ -o .\bin\testing.exe test.cpp

Clang does compile and I get an executable which does run as expected. however I do receive this message.

    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)

I have searched online and can find similar issues but they are not the same.

I realise this maybe simple to you guys, but I am at a loss I have used various IDES and GCC and this code has not produced this warning before.

Robin
  • 311
  • 2
  • 5

1 Answers1

34

Add -Xclang -flto-visibility-public-std to your compiler options.

Like so:

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

Edit:

Or use clang-cl instead:

clang-cl -o test.exe test.cpp

JayPhi
  • 361
  • 3
  • 7
  • 17
    Works, but why? What is clang-cl and what does the option do? – bugybunny Sep 18 '17 at 19:38
  • `clang-cl` is the frontend that uses MSVC cl-like arguments, so e.g. `/std:c++17` instead of `-std=c++17` – LB-- Apr 22 '18 at 22:05
  • Depending on what you are doing, this may or may not be the right solution. See [this answer](https://stackoverflow.com/a/57788067/2659307) for more details and options. – Scott McPeak Sep 04 '19 at 12:08