Author Topic: Microsoft C/C++ compiller  (Read 18231 times)

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Microsoft C/C++ compiller
« on: July 01, 2017, 11:36:31 pm »
What is the best way of configuring a Microsoft C/C++ compiller on Code::Blocks?

I'm getting:
main.o : fatal error LNK1143: invalid or corrupt file: no symbol for COMDAT section 0xB
Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #1 on: July 01, 2017, 11:58:37 pm »
Try reading this: http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Also next time when you ask for help please provide more details like:
1. full build log
2. version information for cb, compiler, os, etc
3. which compiler you've set up inside the cb's compiler settings
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #2 on: July 02, 2017, 03:07:59 am »
1.
Code
-------------- Build: Debug in example_mic (compiler: Microsoft Compiller)---------------

link.exe /nologo /LIBPATH:"..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" /out:bin\Debug\example_mic.exe  obj\Debug\main.obj  /debug
LINK : fatal error LNK1104: cannot open file 'msvcprtd.lib'
Process terminated with status 1104 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

2.
Code::Blocks 16.01
Windows 10

3.
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
« Last Edit: July 02, 2017, 03:10:52 am by lbertolotti »
Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #3 on: July 02, 2017, 09:43:47 am »
This is obviously wrong: /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
You need to pass path where libraries are stored and not where the include files are stored.
Interestingly enough there is no guide how to set vc++ in the wiki any more.  :( :o
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #4 on: July 02, 2017, 04:09:08 pm »
This is obviously wrong: /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
You need to pass path where libraries are stored and not where the include files are stored.
Interestingly enough there is no guide how to set vc++ in the wiki any more.  :( :o

Now I'm gettings this:

Code
-------------- Clean: Debug in example_mic (compiler: Microsoft Compiller)---------------

Cleaned "example_mic - Debug"

-------------- Build: Debug in example_mic (compiler: Microsoft Compiller)---------------

cl.exe /nologo /W3 /EHsc  /MDd /Zi /D_DEBUG    /I"..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib" /c main.cpp /Foobj\Debug\Users\lucao\Desktop\example_mic\main.obj
main.cpp
main.cpp(1): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
Process terminated with status 2 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #5 on: July 02, 2017, 04:36:52 pm »
I don't know what you're doing, but you've swapped the paths for includes and libraries.

The /I options must point to the include folders and /LIBPATH options must point to the library folders.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #6 on: July 02, 2017, 05:25:05 pm »
I don't know what you're doing, but you've swapped the paths for includes and libraries.

The /I options must point to the include folders and /LIBPATH options must point to the library folders.

Yeah, the "Search Directories" option is the one managing the include folders, the "Linker Settings" is the one managing the library folders.

Well, I guess this build log is now ok:
Code
-------------- Build: Debug in example_mic (compiler: Microsoft Compiller)---------------

Target is up to date.
Nothing to be done (all items are up-to-date).

The libraries linked where: msvcprtd.lib, msvcrtd.lib, oldnames.lib, ucrtd.lib, vcruntimed.lib, ucrtd.lib, kernel32.Lib
The search directories are:
..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt
..\..\..\..\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include

But now "Build and run" wants the VCRUNTIME140D_APP.dll.
Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #7 on: July 02, 2017, 05:46:38 pm »
But now "Build and run" wants the VCRUNTIME140D_APP.dll.
You have to install the proper vc runtime in order for your program to be able to find this dll.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #8 on: July 02, 2017, 11:22:39 pm »
In debug mode the compiler wants VCRUNTIME140D_APP.dll, in release mode it wants VCRUNTIME140_APP.dll. I have the latter in Windows\InfusedApps.
Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #9 on: July 03, 2017, 01:32:59 am »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Krice

  • Almost regular
  • **
  • Posts: 150
Re: Microsoft C/C++ compiller
« Reply #10 on: July 03, 2017, 12:58:55 pm »
What is the best way of configuring a Microsoft C/C++ compiller on Code::Blocks?

Is there any reason to use it? What is the problem with gcc?

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Microsoft C/C++ compiller
« Reply #11 on: July 03, 2017, 03:16:50 pm »

I have a writeup for MSCV2013 here. Newer versions of MSVC will need some adaptions.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #12 on: July 03, 2017, 08:33:49 pm »
Is there any reason to use it? What is the problem with gcc?
Uses different abi, so building plugins for other softwares is hard.
Also it produces different symbols, so debugging mixed applications (gcc and vc++) is hard.
Hopefully clang for windows will make it possible to use good free compiler and target the same runtime as vc++.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #13 on: July 03, 2017, 09:17:15 pm »
Newer versions of MSVC will need some adaptions.

Well, I have configured Code::Blocks to compile using Microsoft Visual Studio Build Tools 2017.
Code
-------------- Build: Debug in example_mic (compiler: Microsoft VC 2017)---------------

Target is up to date.
Nothing to be done (all items are up-to-date).


-------------- Run: Debug in example_mic (compiler: Microsoft VC 2017)---------------

Checking for existence: C:\Users\lucao\Desktop\example_mic\bin\Debug\example_mic.exe
Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "C:\Users\lucao\Desktop\example_mic\bin\Debug\example_mic.exe"  (in C:\Users\lucao\Desktop\example_mic\.)
Process terminated with status 0 (0 minute(s), 1 second(s))

Where is the Code::Blocks global compiler settings file stored?
Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Microsoft C/C++ compiller
« Reply #14 on: July 03, 2017, 10:12:58 pm »
It depends. Most of the settings are stored in default.conf in you appdata/codeblocks folder. But some of the compiler settings are stored in separate files inside this folder.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #15 on: July 03, 2017, 10:46:31 pm »
Running on Windows 10 64-bit, Code::Blocks 16.01 Console Application

Toolchain executable:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64

Search directories:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt

Debug Linker:
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/libcpmt.lib" />
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/libcmt.lib" />
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/oldnames.lib" />
<Add library="../../../../Program Files (x86)/Windows Kits/10/Lib/10.0.15063.0/um/x64/Uuid.Lib" />
<Add library="../../../../Program Files (x86)/Windows Kits/10/Lib/10.0.15063.0/um/x64/kernel32.Lib" />
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/libvcruntime.lib" />
<Add library="../../../../Program Files (x86)/Windows Kits/10/Lib/10.0.15063.0/ucrt/x64/libucrt.lib" />

Release linker:
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/libcpmt.lib" />
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/libcmt.lib" />
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/oldnames.lib" />
<Add library="../../../../Program Files (x86)/Windows Kits/10/Lib/10.0.15063.0/um/x64/Uuid.Lib" />
<Add library="../../../../Program Files (x86)/Windows Kits/10/Lib/10.0.15063.0/um/x64/kernel32.Lib" />
<Add library="../../../../Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.25017/lib/x64/libvcruntime.lib" />
<Add library="../../../../Program Files (x86)/Windows Kits/10/Lib/10.0.15063.0/ucrt/x64/libucrt.lib" />

All files were obtained through Visuak Studio Build Tools 2017. Large projects will, of course, need more files.
Languages: C/C++, SQL, HTML, VB, Python and R

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Microsoft C/C++ compiller
« Reply #16 on: July 04, 2017, 04:22:20 am »
Why do you have these strange relative paths to the libraries? Actually why do you have paths to libraries at all? Usually you just specify search directories and add libraries by name only. Also you link runtime libraries explicit, this should be wrong, at least for the basic libraries, not sure about WinRT and the like. The compiler picks the proper ones itself depending on the used switches, e.g. /MT or /MD.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Microsoft C/C++ compiller
« Reply #17 on: July 04, 2017, 10:08:12 am »
Well, I have configured Code::Blocks to compile using Microsoft Visual Studio Build Tools 2017.

Can you share the configuration settings?

As mentioned, the settings are mostly in  default.conf

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Microsoft C/C++ compiller
« Reply #18 on: July 04, 2017, 04:18:07 pm »
Well, I have configured Code::Blocks to compile using Microsoft Visual Studio Build Tools 2017.

Can you share the configuration settings?

I already shared the configuration settings.

Why do you have these strange relative paths to the libraries? Actually why do you have paths to libraries at all? Usually you just specify search directories and add libraries by name only. Also you link runtime libraries explicit, this should be wrong, at least for the basic libraries, not sure about WinRT and the like. The compiler picks the proper ones itself depending on the used switches, e.g. /MT or /MD.

If you think you can do better, then show us how to do it.
Languages: C/C++, SQL, HTML, VB, Python and R

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Microsoft C/C++ compiller
« Reply #19 on: July 04, 2017, 07:30:01 pm »
You have to differentiate between two types of compiler configuration, the global one and the project specifc one. In the global configuration i put everything that is required to build for a specific target environment, in the project one (which are multiple in fact) i put everything required for the specific project configuration, in my case its Debug and Release.

I dont have Visual Studio 2017 and i dont build for x64, i have Visual Studio 2015 and i build for x32 with the Windows XP toolkit, so my paths are different than yours and i need some extra settings, but this should outline the steps anyway.

Code
Global Configuration
Compiler settings / Other compiler options
/FS  -> required for parallel build to work

Compiler settings / #defines
_USING_V110_SDK71_  -> required for Windows XP toolkit

Search directories / Compiler
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include  -> required for Windows XP toolkit
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt

Search directories / Linker
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\lib  -> required for Windows XP toolkit
C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x86

Search directories / Resource compiler
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include  -> required for Windows XP toolkit
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt

Toolchain executables / Compiler's installation directory
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC

Toolchain executables / Additional Paths
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\bin

Other Settings / Advanced options / Link object files to executable
$linker /nologo /subsystem:windows,5.01 $libdirs /out:$exe_output $libs $link_objects $link_resobjects $link_options  -> required for Windows XP toolkit

Other Settings / Advanced options / Link object files to console executable
$linker /nologo /subsystem:console,5.01 $libdirs /out:$exe_output $libs $link_objects $link_resobjects $link_options  -> required for Windows XP toolkit

Now the following project settings are almost like the defaults that Visual Studio uses itself (note: the command line compiler DOES NOT use these as defaults, thats why i have to specify them)

Code
Debug Configuration
Compiler settings / Compiler Flags
/Zi
/W4
/Od
/fp:precise
/GR
/RTCsu
/Gm
/MDd

Compiler settings / Other compiler options
/EHsc

Compiler settings / #defines
_CRT_SECURE_NO_DEPRECATE  -> to get rid of annoying warnings of otherwise perfect standard compliant code
_DEBUG
UNICODE
_UNICODE

Linker settings / Other linker options
/DEBUG
/INCREMENTAL
/MANIFEST
/DYNAMICBASE
/NXCOMPAT
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"

Code
Release Configuration
Compiler settings / Compiler Flags
/W4
/O2
/fp:precise
/GR
/MD

Compiler settings / Other compiler options
/EHsc

Compiler settings / #defines
_CRT_SECURE_NO_DEPRECATE  -> to get rid of annoying warnings of otherwise perfect standard compliant code
NDEBUG
UNICODE
_UNICODE

Linker settings / Other linker options
/INCREMENTAL:NO
/MANIFEST
/DYNAMICBASE
/NXCOMPAT
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"

This is enough to build simple Hello World console applications. Depending on your project you need to add additional search directories for the compiler and linker and add your libraries to link with, but you only add them by name, e.g. you add under Link libraries kernel32 and uuid without path, they are searched for in the paths you defined in the Global Configuration.