# Visual Studio link error

**URL:** <https://root-forum.cern.ch/t/visual-studio-link-error/51625>\
**Category:** Newbie\
**Created:** [September 20, 2022, 1:19pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625 "2022-09-20T13:19:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [September 20, 2022, 1:19pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/1 "2022-09-20T13:19:31Z")

</div>

I am trying to compile the simple example in Visual Studio 2022. Windows 10, Root just installed yesterday: 6.26/06. I created a console project in Visual Studio and then added the include path to the project include settings and the library path to the project library settings. It compiles correctly but gives the 2 linker errors:

| Severity | Code | Description | Project | File | Line | Suppression State |
| --- | --- | --- | --- | --- | --- | --- |
| Error | C2445 | result type of conditional expression is ambiguous: types ‘TString’ and ‘const char [1]’ can be converted to multiple common types | roottestplot | C:\Program Files\rootfiles\root\include\TF1.h | 463 | |
| Error | C4996 | ‘std::iterator\<std::bidirectional\_iterator\_tag,TObject \*,ptrdiff\_t,const TObject \*\*,const TObject \*&\>’: warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator\_category, value\_type, difference\_type, pointer, and reference. Note that value\_type is required to be non-const, even for constant iterators. You can define \_SILENCE\_CXX17\_ITERATOR\_BASE\_CLASS\_DEPRECATION\_WARNING or \_SILENCE\_ALL\_CXX17\_DEPRECATION\_WARNINGS to acknowledge that you have received this warning. | roottestplot | C:\Program Files\rootfiles\root\include\TList.h | 198 | |

What did I miss in setting this up?

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 20, 2022, 1:23pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/2 "2022-09-20T13:23:30Z")

</div>

Welcome to the ROOT forum.  
I think @bellenot can help you when he’ll be back.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [September 20, 2022, 4:19pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/3 "2022-09-20T16:19:06Z")

</div>

This has been resolved in the main branch and the v6.26 patch branch (i.e. the upcoming v6.28/00 and v6.26/08)

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [September 20, 2022, 5:01pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/4 "2022-09-20T17:01:39Z")

</div>

So, this fix is not yet available? I don’t see it anywhere.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [September 20, 2022, 5:18pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/5 "2022-09-20T17:18:25Z")

</div>

It is currently available only if you build from source.

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [September 20, 2022, 5:40pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/6 "2022-09-20T17:40:12Z")

</div>

Oh, swell. I’ll wait.

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [January 24, 2023, 12:48pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/7 "2023-01-24T12:48:41Z")

</div>

I am still getting the same C2445 error in Visual Studio with release 6.26/10. The C4996 error no longer occurs when trying to compile your basic example.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 24, 2023, 1:03pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/8 "2023-01-24T13:03:37Z")

</div>

Can you give more details about how you build your example, like which exact version of Visual Studio, and with which compiler flags?

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [January 24, 2023, 2:51pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/9 "2023-01-24T14:51:55Z")

</div>

The complete error message is:

Severity Code Description Project File Line Suppression State  
Error C2445 result type of conditional expression is ambiguous: types ‘TString’ and ‘const char [1]’ can be converted to multiple common types roottestplot C:\root\_v6.26.10\include\TF1.h 463

The compile switches seem to be /RTC1 /Gd /permissive- /EHsc /Gm- /fp:precise /ZcforScope

/Od /Zc:inline /MDd /sdl /GS /JMC /nologo /WX- /Zc:wchar\_t /FC /W3

Preprocessor definitions:

\_DEBUG  
\_CONSOLE

Hope this is sufficient. Thanks

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 24, 2023, 3:06pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/10 "2023-01-24T15:06:17Z")

</div>

OK, so I suppose you build from inside Visual Studio, right? Can you try to compile on the Visual Studio command prompt corresponding to your version of Visual Studio (what I was asking for) and for the architecture you’re building with this command:

```auto
cl -nologo -MD -GR -EHsc -Zc:__cplusplus -std:c++17 [your source files] -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib

```

(and add the libraries you need for your project)

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [January 24, 2023, 3:12pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/11 "2023-01-24T15:12:17Z")

</div>

Visual Studio 2022 17.4.3, v 143

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 24, 2023, 3:16pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/12 "2023-01-24T15:16:57Z")

</div>

OK, so open a `x86 Native Tools Command Prompt for VS 2022` for 32 bit build, or a `x64 Native Tools Command Prompt for VS 2022` for 64 build, and after calling `thisroot.bat` (in the bin directory of where you installed ROOT), type the command I posted previously

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [January 24, 2023, 4:02pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/13 "2023-01-24T16:02:50Z")

</div>

Well, it compiles, but I am getting link errors to TF1 and TCanvas. This is real progress, though.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 24, 2023, 4:04pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/14 "2023-01-24T16:04:49Z")

</div>

Then add `libGpad.lib` and `libHist.lib`, and most probably `libGui.lib`

---

<div class="post-metadata">

**Author:** ![jcooper](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jcooper](https://root-forum.cern.ch/u/jcooper)\
**Post date:** [January 24, 2023, 4:44pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/15 "2023-01-24T16:44:08Z")

</div>

That did it. Thank you very much.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 24, 2023, 4:46pm UTC](https://root-forum.cern.ch/t/visual-studio-link-error/51625/16 "2023-01-24T16:46:17Z")

</div>

You’re welcome. And BTW, you should use CMake for your projects, that would be much easier
