<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>If the environment is set up correctly, the MSVC tools should be
able to find the correct versions of the runtime libraries
automatically. If you are using the wrapper script approach, the
problem is most likely that when using MSVC, linking is done by
calling the linker directly instead of indirectly via the compiler
driver (as is common on Unix-like systems). So you also need a
wrapper for link.exe that sets up the environment, and tell CMake
to use that by setting CMAKE_LINKER to the name of the wrapper
script.</p>
<p>With kind regards,<br>
Eric<br>
</p>
<div class="moz-cite-prefix">Am 18.09.19 um 18:39 schrieb Joao Pedro
Abreu De Souza:<br>
</div>
<blockquote type="cite"
cite="mid:CAB57kXp8dwe=adCz8Rq3g6PUaYRQo87-sXU-7JHAa9ViTgYHXg@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Cool. I try using this toolchain in a toy project,
just to test, and execute the cmake inside cross-compiling
x64_x86 from visual studio 2017 and all work as expected, except
the linking from ninja, that break because cannot find printf.
<div>Is absolutely cool, better than my last toolchain. Do you
know how Can I link with libc from visual studio 2013(that was
your example)? From location on 2013, the 2017 can be deduced,
I think.</div>
<div><br>
</div>
<div>To make clear, when I said how to link with libc, is
literally the path that I don't know kkkk, I know that must
use libpath(or set LIB env variable) with the path, but what
path? kkk</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Em qua, 18 de set de 2019 às
02:50, Eric Doenges <<a href="mailto:doenges@mvtec.com"
moz-do-not-send="true">doenges@mvtec.com</a>> escreveu:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>We use ninja for building on Windows. Our toolchain file
for the MSVC compiler is really simple (this is for MSVC
18.0, 32 bits):</p>
<p>--- SNIP ---<br>
</p>
<p><tt>set(CMAKE_SYSTEM_NAME Windows)</tt><tt><br>
</tt><tt>set(CMAKE_SYSTEM_PROCESSOR "x86")</tt><tt><br>
</tt><tt>set(CMAKE_SYSTEM_VERSION 1)</tt><tt><br>
</tt><tt><br>
</tt><tt># Microsoft MSVC compiler</tt><tt><br>
</tt><tt>set(CMAKE_C_COMPILER cl.exe)</tt><tt><br>
</tt><tt>set(CMAKE_CXX_COMPILER cl.exe)</tt><tt><br>
</tt><tt><br>
</tt><tt># Unfortunatly CMake doesn't seem to know
anything about the MSVC compiler,</tt><tt><br>
</tt><tt># so tell CMake that cl.exe supports C99</tt><tt><br>
</tt><tt>set(CMAKE_C_COMPILE_FEATURES c_std_99)</tt><tt><br>
</tt><tt><br>
</tt><tt># If Visual Studio is selected as generator, only
allow VS 2013</tt><tt><br>
</tt><tt>if(CMAKE_GENERATOR MATCHES "Visual Studio")</tt><tt><br>
</tt><tt> if(NOT CMAKE_GENERATOR MATCHES "Visual Studio
12 2013")</tt><tt><br>
</tt><tt> message(FATAL_ERROR "Visual Studio generator
requires Visual Studio 12 2013"</tt><tt><br>
</tt><tt> " for this configuration")</tt><tt><br>
</tt><tt> else()</tt><tt><br>
</tt><tt> # Enable parallel builds for Visual Studio
Projects with the /MP flag</tt><tt><br>
</tt><tt> set(_MP_FLAG "/MP")</tt><tt><br>
</tt><tt> endif()</tt><tt><br>
</tt><tt>endif()</tt></p>
<p><tt>set(CMAKE_C_FLAGS_INIT "/arch:SSE2 ${_MP_FLAG}
/EHsc")</tt><tt><br>
</tt><tt>set(CMAKE_CXX_FLAGS_INIT "/arch:SSE2
${_MP_FLAG}")</tt><br>
</p>
<p>--- SNIP ---<br>
</p>
<p>However, there is a major snag (naturally, since we're
talking about Windows here) - in order for the Microsoft
compiler to work from the command line, you need to set
the correct environment, and CMake doesn't really give you
a good way to do this. You can set environment variables
from CMake, but as the documentation says "This command
affects only the current CMake process, not the process
from which CMake was called, nor the system environment at
large, nor the environment of subsequent build or test
processes.".</p>
<p>The solution we use is instead of calling cmake directly,
we call a Perl script that sets up the environment
correctly and then calls cmake for configuration or
building. An alternative solution would be to write a
batch script wrapper for cl.exe, something like.<br>
</p>
<p><tt>@ECHO OFF</tt><tt><br>
</tt><tt>"C:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\vcvarsall.bat" x86</tt><tt><br>
</tt><tt>cl.exe %*</tt><br>
</p>
<p>and then set this batch script as the C and C++ compiler
in CMake (note that this is untested - I think it should
work, but it may need some extra work).</p>
<p>With kind regards,<br>
Eric<br>
</p>
<div class="gmail-m_92730801547785318moz-cite-prefix">Am
17.09.19 um 21:46 schrieb fdk17:<br>
</div>
<blockquote type="cite">
<div>As I recall for myself, simply using the Visual
Studio Generator with the -A option was all that was
needed to build for Win32.<br>
</div>
<div>You don't need a toolchain file because the generator
already knows how to setup a Visual Studio Project to
target Win32.<br>
</div>
<div>Even the documentation for cross-compiling doesn't
show a need to setup toolchain file for cross compiling
in this case.<br>
</div>
<div><br>
</div>
<div>I personally never seen anyone try to use the Ninja
generator via command line CMake and use the cl.exe
compiler.<br>
</div>
<div>I've only seen that using Visual Studio to open a
CMakeLists.txt file it can produce a Ninja project. But
even MS documentation states that it doesn't always
work.<br>
</div>
<div><br>
</div>
<div><a
href="https://stackoverflow.com/questions/31262342/cmake-g-ninja-on-windows-specify-x64"
target="_blank" moz-do-not-send="true">https://stackoverflow.com/questions/31262342/cmake-g-ninja-on-windows-specify-x64</a><br>
</div>
<div>This says you should be able to open the proper
development window and use Ninja.<br>
</div>
<div><br>
</div>
<div>The output shows that in the environment you are
using it doesn't even know how to use cl.exe to even
determine with compiler it is. Maybe not all the proper
environment variables and paths are being set correctly
when using the compiler.<br>
</div>
<div><br>
</div>
<div>--<br>
</div>
<div>F<br>
</div>
</blockquote>
<div class="gmail-m_92730801547785318moz-signature">-- <br>
<div
style="width:480px;text-align:left;font-family:Arial,Helvetica,sans-serif">
<p
style="color:rgb(6,45,100);font-size:14px;text-align:left;font-family:Arial,Helvetica,sans-serif">
<b>Dr. Eric Dönges</b> <br>
Senior Software Engineer </p>
<p
style="color:rgb(6,45,100);font-size:12px;text-align:left;font-family:Arial,Helvetica,sans-serif">MVTec
Software GmbH | Arnulfstr. 205 | 80634 Munich |
Germany <br>
<a
style="font-size:12px;font-family:Arial,Helvetica,sans-serif;color:rgb(6,45,100)"
href="mailto:mustermann@mvtec.com" target="_blank"
moz-do-not-send="true">doenges@mvtec.com</a> | Tel:
+49 89 457 695-0 | <a
style="font-size:12px;font-family:Arial,Helvetica,sans-serif;color:rgb(6,45,100)"
href="http://www.mvtec.com" target="_blank"
moz-do-not-send="true">www.mvtec.com</a> <br>
</p>
<p> <span
style="font-size:12px;font-family:Arial,Helvetica,sans-serif;color:rgb(6,45,100)">Find
our privacy policy <a
style="font-size:12px;font-family:Arial,Helvetica,sans-serif;color:rgb(6,45,100)"
href="https://www.mvtec.com/imprint"
target="_blank" moz-do-not-send="true">here</a>.</span>
</p>
<p
style="color:rgb(6,45,100);font-size:12px;text-align:left;font-family:Arial,Helvetica,sans-serif"><img
src="https://mvtec.com/fileadmin/Redaktion/newsletter/mail-signature/newsletter-icon.png"
valign="bottom" moz-do-not-send="true" width="16"
height="16"> <a
style="font-size:12px;font-family:Arial,Helvetica,sans-serif;color:rgb(6,45,100);font-weight:bold"
href="https://www.mvtec.com/newsletter"
target="_blank" moz-do-not-send="true">Sign up</a>
for our MVTec Newsletter!</p>
<p
style="margin:0px;color:rgb(102,102,102);font-size:12px;text-align:left;font-family:Arial,Helvetica,sans-serif">Geschäftsführer:
Dr. Wolfgang Eckstein, Dr. Olaf Munkelt<br>
Amtsgericht München HRB 114695</p>
<p
style="margin:0px;color:rgb(102,102,102);font-size:12px;text-align:left;font-family:Arial,Helvetica,sans-serif"> </p>
<img
src="https://www.mvtec.com/fileadmin/Redaktion/newsletter/mail-signature/mvtec-logo-line.png"
alt="MVTec Software GmbH Logo" moz-do-not-send="true"></div>
</div>
</div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer"
target="_blank" moz-do-not-send="true">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a
href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer"
target="_blank" moz-do-not-send="true">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake
community. For more information on each offering, please
visit:<br>
<br>
CMake Support: <a
href="http://cmake.org/cmake/help/support.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a
href="http://cmake.org/cmake/help/consulting.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a
href="http://cmake.org/cmake/help/training.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a
href="http://www.kitware.com/opensource/opensource.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote>
</div>
</blockquote>
<div class="moz-signature">-- <br>
<div style="width:480px; text-align: left; font-family: Arial,
Helvetica, sans-serif;">
<p style="color: #062d64; font-size: 14px; text-align: left;
font-family: Arial, Helvetica, sans-serif;">
<b>Dr. Eric Dönges</b>
<br>
Senior Software Engineer
</p>
<p style="color: #062d64; font-size: 12px; text-align: left;
font-family: Arial, Helvetica, sans-serif;">MVTec Software
GmbH | Arnulfstr. 205 | 80634 Munich | Germany
<br>
<a style="font-size: 12px; font-family: Arial, Helvetica,
sans-serif; color: #062d64;"
href="mailto:mustermann@mvtec.com">doenges@mvtec.com</a> |
Tel: +49 89 457 695-0 | <a style="font-size: 12px;
font-family: Arial, Helvetica, sans-serif; color: #062d64;"
href="http://www.mvtec.com">www.mvtec.com</a>
<br>
</p>
<p>
<span style="font-size: 12px; font-family: Arial, Helvetica,
sans-serif; color: #062d64;">Find our privacy policy <a
style="font-size: 12px; font-family: Arial, Helvetica,
sans-serif; color: #062d64;"
href="https://www.mvtec.com/imprint">here</a>.</span> </p>
<p style="color: #062d64; font-size: 12px; text-align: left;
font-family: Arial, Helvetica, sans-serif;"><img
src="https://mvtec.com/fileadmin/Redaktion/newsletter/mail-signature/newsletter-icon.png"
valign="bottom" width="16" height="16"> <a style="font-size:
12px; font-family: Arial, Helvetica, sans-serif; color:
#062d64; font-weight: bold;"
href="https://www.mvtec.com/newsletter">Sign up</a> for our
MVTec Newsletter!</p>
<p style="margin: 0px; color: #666; font-size: 12px; text-align:
left; font-family: Arial, Helvetica, sans-serif;">Geschäftsführer:
Dr. Wolfgang Eckstein, Dr. Olaf Munkelt<br>
Amtsgericht München HRB 114695</p>
<p style="margin: 0px; color: #666; font-size: 12px; text-align:
left; font-family: Arial, Helvetica, sans-serif;"> </p>
<img
src="https://www.mvtec.com/fileadmin/Redaktion/newsletter/mail-signature/mvtec-logo-line.png"
alt="MVTec Software GmbH Logo"></div>
</div>
</body>
</html>