Compiling C++ programs in Sublime Text 2 - g++

I installed the git-cmd.bat command prompt so I could do RoR. I forgot where I got this. Anyway, the git-cmd.bat has g++ installed or something (I don't know why and would love to learn!).
For class I need to make sure my projects run on visual studios and on g++. I like to write my programs in a sublime then transfer over to the ide to test then transfer back and fix code. This is getting very tedious and writing g++ -o asdf *.cpp every single time is not ideal.
When I do ctrl+b in sublime, it give me this error:
[Error 2] The system cannot find the file specified
[cmd: [u'g++', u'C:\\Users\Desktop\\Project 2\\main.cpp', u'-o', u'C:\\Users\\\Desktop\\Project 2/main']]
[dir: C:\Users\s\Desktop\Project 2]
[path: C:\windos\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\MATLAB\R2013a\runtime\win64;C:\Program Files\MATLAB\R2013a\bin;C:\Ruby193\bin]
[Finished]
I thought g++ was already installed and since I can run g++ in my git command prompt, it should already be in path. Can anyone help me out please?
Thanks!

Hey not sure if you figured this out, but it is checking the directories listed in path.
So you'll have to add the path to g++ in the system path: http://www.computerhope.com/issues/ch000549.htm
or where it says "g++" you'll have to add the absolute path to the executable. For example, instead of downloading MinGW twice, I have linked to the Code::Blocks (my IDE of choice) version of MinGW and the "g++" now says:
C:\Program Files (x86)\CodeBlocks\MinGW\bin\g++
(each slash is twice above, StackOverflow is escaping the string)
I'm not familiar with the "git-cmd.bat prompt" you mention, but if it does have g++ you'd have to find the path to it and do one of the above. If StackOverflow/Google can't shed light on this I would recommend just doing a search for g++ in Windows Explorer.

Related

clion wsl "CMake 3.20 or higher is required. You are running version 3.16.3"

so I just downloaded wslusing the wsl --install command using PowerShell
now I'm trying to connect it to Clion which works
i cant add images so here is a link to it
but when i'm tying to build the project i get this error
"CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.20 or higher is required. You are running version 3.16.3"
my cmake file:
cmake_minimum_required(VERSION 3.20)
project(ex2 C)
set(CMAKE_C_STANDARD 99)
add_executable(ex2
ex2.c ex2.h
main1.c
main2.c)
i tried updating wsl using wsl --update (in powershell)
The CMake installation inside the WSL is used. Unfortunately currently snap doesn't seem to be available in WSL, but installing the latest CMake version isn't too complicated nonetheless:
(optional) uninstall the old cmake installation in WSL; personally I don't see any benefit in multiple CMake installations, but there may be valid reasons for this. Most likely this will just makes the use of cmake more complex, since you need to remember which cmake version is used.
Download the appropriate cmake version from the cmake website ( https://cmake.org/download/ ). The version to choose is the tar.gz file under binary distributions for the x86_64 target. To get version 3.21.4 (currently the latest release), you can download the file from https://github.com/Kitware/CMake/releases/download/v3.21.4/cmake-3.21.4-linux-x86_64.tar.gz (Identical to the link on the CMake download page).
Unpack the archive from WSL. Navigate to the directory where you want the cmake installation to recide. This will add the cmake-3.21.4-linux-x86_64 directory containing all the files required to work with cmake to the current working directory. Let's assume you want to add the cmake files to the /opt directory. Furthermore let's assume the windows user name to be fabian, C: to be the primary hard drive and the download to be saved to the Downloads directory in the user directory:
cd /opt
tar -xf /mnt/c/Users/fabian/Downloads/cmake-3.21.4-linux-x86_64.tar.gz
(optional) make CMake available without specifying the path; this could be done as described here: https://unix.stackexchange.com/questions/3809/how-can-i-make-a-program-executable-from-everywhere ; don't do this, if an existing cmake installation is already available in the command line assuming you did install cmake to /opt, the cmake binary recides at /opt/cmake-3.21.4-linux-x86_64/bin
You should now be able to use cmake specifying either the full path to the executable (/opt/cmake-3.21.4-linux-x86_64/bin/cmake assuming you used the /opt directory) or directly via a command after opening the WLS commandline again (provided you followed step 4).
Now the only thing left to do should be telling CLion about the location of the cmake executable. Note that I haven't tested this, since I don't use this IDE. It's working fine using Visual Studio Code though...

What is the cause for this invalid path issue when trying to run cpp protocol buffer compiler from CMake on Windows 10 and how can I solve it?

I'm trying to build the aasdk project on a Windows 10 computer. To do this, I am attempting to run the following commands in the root of the git repo directory:
mkdir buildDir
cd buildDir
cmake ..\
cmake --build . --config Release
The last command is obviously the one that's failing. I get the following output when I run that command:
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- Found libusb-1.0:
-- - Includes: C:/libusb-master/x64/Release
-- - Libraries: C:/libusb-master/x64/Release/lib/libusb-1.0.lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/aasdk-development/buildDir
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(200
,5): warning MSB8062: Custom build for item "C:\aasdk-development\buildDir\CMakeFiles\b2b8e2a3c1aae1e014a7c3c3f8aadde7\AVCha
nnelData.pb.h.rule" specifies invalid path "C:\aasdk-development\buildDir\aasdk_proto\protobuf::protoc" as an additional dep
endency. This may cause incremental build to work incorrectly. [C:\aasdk-development\buildDir\aasdk_proto\aasdk_proto.vcxpro
j]
...
Running cpp protocol buffer compiler on C:/aasdk-development/aasdk_proto/AVChannelData.proto
The filename, directory name, or volume label syntax is incorrect.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(238
,5): error MSB8066: Custom build for 'C:\aasdk-development\buildDir\CMakeFiles\b2b8e2a3c1aae1e014a7c3c3f8aadde7\AVChannelDat
a.pb.h.rule;...' exited
with code 123. [C:\aasdk-development\buildDir\aasdk_proto\aasdk_proto.vcxproj]
Where ... is the same message repetead for each *.proto file inside aasdk_proto directory. From what I can tell, it seems it thinks some paths are invalid. What I can't tell, is which paths and in what way are they invalid.
After the first comment, I decided to check where it gets those paths. Below is the content of the CMakeLists.txt for protobuf, found in the aasdk_proto directory:
include(FindProtobuf)
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIR})
file(GLOB_RECURSE proto_files ${CMAKE_CURRENT_SOURCE_DIR}/*.proto)
protobuf_generate_cpp(proto_sources proto_headers ${proto_files})
add_library(aasdk_proto SHARED ${proto_headers} ${proto_sources})
target_link_libraries(aasdk_proto ${PROTOBUF_LIBRARIES})
Of interest is the 5th line which enumerates all the *.proto files in the relevant directory before calling protobuf_generate_cpp, the part which I believe to be causing the errors.
Adding message(STATUS ProtoFiles: ${proto_files}) after line 5 to print the paths yielded correct values, atleast to my eyes:
C:/aasdk-development/aasdk_proto/AbsoluteInputEventData.proto;C:/aasdk-development/aasdk_proto/AbsoluteInputEventData.proto;...
I replaced the forward slash with a backslash just for giggles, since that's how Windows likes them, but that didn't work.
I'm a bit late, but for anyone still having this problem, I ran into a similar issue while building CuraEngine, and found the cause. In my case, I had to set the path to protoc.exe with both variables PROTOC and Protobuf_PROTOC_EXECUTABLE. (I had only set PROTOC and CMake didn't throw any errors.)
I imagine the situation with aasdk must be similar. Some variable (probably PROTOBUF_PROTOC_EXECUTABLE?) that tells the location of protoc.exe must be missing.

How to tell CMake where to find the compiler?

I am trying to install slycot and I get the following issue.
The CMAKE_C_COMPILER: cl is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH
I downloaded Visual Studio 2019. I tried to run "CMake" from a VS command prompt, but nothing happens.
I have found the vcvarsall.bat file location in the VS folder, but I do not know what to do with it. Would anyone be so kind to tell me what to do next? (I am new to scripting, so please be explicit).
Thanks
Normally cmake uses the program vswhere.exe to detect your VS2019 installation. But sometimes this seems not to work.
You can run the
vcvarsall.bat Win64
to setup the environment variables in the command prompt. How to find the path to it can be found here. And I am pretty sure the script vcvarsall.bat will show you the option when calling it without a parameter.

Google GMOCK build libgmock.a under windows

I try to build the gmock library from google under windows, avialable on github from here:
https://github.com/google/googletest/tree/master/googlemock
I tried to use cmake in the cygwin console, but I could not build it.
cmake C:\Users\Username\Downloads\googlemock-master\googlemock-master\googlemock
"CMake Error: The source directory "C:UsersSETDownloadsgooglemock-mastergooglemock-mastergooglemock" does not exist.
Specify --help for usage, or press the help button on the CMake GUI."
Then I installed visual studio 2017 and opened the gmock.sln file, but also this build failed.
"Error C1083: "gtest/internal/gtest-linked_ptr.h": No such file or directory gmock C:\Users\Username\Downloads\googlemock-master\googlemock-master\googlemock\include\gmock\internal\gmock-port.h"
Does anyone have an idea how I could build this library under windows 10?
Edit: Ok, for cmake the path needs to have /../ and not ..\, but i still don't get which path I need to include in cmake
Very simple:
Under the googlemock folder, create a new folder, named build (for example);
cd build && cmake ..
Basically, you're creating a new folder for the build (preferably inside the project tree, but not necessary), cd into it, and run cmake <dir>, where <dir> is the path to CMakeLists.txt, which contains the recipe for generating the build.
That's it. Now you'll have a generated gmock.sln, which you could build with Visual Studio.
For CMake to generate Visual Studio projects, you should have the Visual Studio binaries and Windows SDK reachable from your PATH.
Finally, you need to specify a generator, using CMake's -G parameter, for telling CMake which Visual Studio version you'd like projects to be generated for.
Example of putting this together:
set PATH="C:\Program Files\Microsoft Visual Studio 14.0\VC\bin";"c:\Program Files\Windows Kits\8.1\bin\x86";%PATH%
cd build
cmake -G "Visual Studio 14 2015" ..
For additional instructions, you may refer to googletest github page:
https://github.com/google/googletest/blob/master/googletest/README.md#using-cmake

Compiling clang/LLVM on win results in compile errors - how to fix?

I've stumbled upon problems installing clang/LLVM on my Win 7 64-bit machine for setting up Emscripten in my Visual Studio 2010 Setup. I was following the official howto from Emscripten at https://github.com/kripken/emscripten/wiki/Using-Emscripten-on-Windows and stumbled into problems regarding the needed compilation of clang/LLVM.
svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_32/final llvm
cd llvm\tools
svn co http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_32/final clang
cd ..\\..
mkdir build
cmake -G "Visual Studio 10" ..\llvm
msbuild LLVM.sln /p:Configuration=Release
The result is alot of errors similiar to this one:
CUSTOMBUILD : error : error reading '10.0\VC\bin\llvm\tools\clang\test\Index\
pch-opaque-value.cpp' [c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\b
in\build\tools\clang\test\check-clang.vcxproj]
CUSTOMBUILD : error : error reading '10.0\VC\bin\llvm\tools\clang\test\Index\
pch-with-errors.m' [c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\
build\tools\clang\test\check-clang.vcxproj]
Obviously, a path starting at
'10.0\VC...' is totally invalid.. its missing the 'C:\Program Files (x86)\Microsoft Visual Studio ' in front.. (I've checked there is a file like that in test\Index\ - it is!
My question is: how do I fix that ?
a) Can I setup an additional include path that is like 'C:\folder\MS Visual ' (including space) ?
What I have tried so far:
a) Doing it from Visual Studio Prompt and normal Prompt. Using default and custom location.
b) Running MSBUILD like
msbuild LLVM.sln /p:Configuration=Release /p:"VCBuildAdditionalOptions= C:\Program Files (x86)\Microsoft Visual Studio "
c) Trying to change PATH/Systemroot.. Destroyed my systemroot in the meantime for unknown reasons (It complaimed about a wrong path like "C:\Program " and erased it obviously).
I am seriously stuck and dont know any further than these steps. Setting up an include path does not seem to help - though I'm wondering if the CMAKE stuff had problems with space's or what is going on.
Since the authors of Emscripten and probably LLVM call their windows support "experimental", I'm not the only one having troubles trying to set up LLVM/clang for later use with Visual Studio 2010 (not 2012..). I'm sorry for the bad formatting, for some reason SO won't allow me neat formatting today.. I'm using a nightly browser build though.
If you just need a build of LLVM, you can generate NMake Makefiles and build with nmake instead of msbuild. It seems that there is a quoting issue somewhere (might be CMake, CmakeLists.txt, msbuild, who knows).
On second thought, this might be a problem with environment variables. How did you set up PATH? Try from a new "Visual Studio Developer Command Prompt".