Configuring C++ SDK in Intellij IDEA for Windows - c++

I'm trying to configure Intellij to create C/C++ projects. The plugin was installed successfully but when I go to create a new project, I have to setup a Cpp SDK. Is This a path to GCC home or similar (I try it but doesn't works)? How can I perform this configuration?

Here is detailed about the configuration:
Install the plugin. There will appear no special project type for C/C++ projects. Just take/create any Java project, and the plugin will process all *.c/*.cc/*.cpp source files from the project source roots.
Then you need to specify the C/C++ dialect. Open Settings->IDE Settings->C/C++. There are three options, which can be used for tuning:
Compiler selector — you may choose between GCC and MS VC dialects
Use C dialect — this option makes the compiler to treat the sources like C, not CPP files.
GCC executable name — gcc is used if this field is left blank. This option is important for GCC configuration autodetection.
To parse the files you also need to specify include paths for your C/C++ environment. Currently, the plugin can automatically detect GCC include paths, in case of other compilers you need to specify the include paths by yourself. Additional include files can be specified for each project separately. Automatic gcc include paths detection works only if your compiler presents in path. If it does not (or if you want to use include-paths of a non-default compiler), then you should specify the name (full name, if necessary) of gcc executable in GCC executable name field.
UPDATE: I would suggest you to try JetBrain's CLion - The intelligent cross-platform C/C++ IDE for cross platform development.
If you are using Visual Studio then use Resharper C++. ReSharper C++ makes Microsoft Visual Studio a much better IDE with refactorings, navigation, code inspections, quick-fixes, code generation and more productivity features for C++ development.

Related

What's the right way to work with a different C++ compiler in a CDT project?

I use Eclipse CDT Mars.2 (and Neon RC), on Linux. My distribution's default C++ compiler is GCC 5.3.1, but for some of my work I use GCC 4.9.3. I would like everything regarding my project to use GCC 4.9.3: The tool discovery, the C++ standard library, the include file paths, the indexer, the preprocessing - all of it.
What's the right way to do this? It seems Eclipse has rather byzantine "providers" and "toolchains" configurations and I do not want to make settings I won't be able to undo later...
Note:
I did try to replace ${COMMAND} with /usr/bin/g++-4.9 in some of the Preprocessor Includes etc. provider settings, and this did result in 4.9.3-related include files being discovered, but my indexer didn't like that and all of the std::stuff showed up red and unresolved. Then I tried looking for where I set the compiler version used for indexing but I couldn't find that.
There are two possible answers, depending on whether you are doing "Standard Make" or "Mangaged Make". Standard Make means you are writing your own Makefiles and managing all that yourself. Managed Make means you are letting CDT create the Makefiles and manage them.
Standard Make
For standard make, everything is controlled by what the scanner discovers. The scanner handles finding all the system include files that are part of your project, and those are fed into the indexer to resolve symbols and also allows things like header file navigation.
To change the compiler that is used, you need replace ${COMMAND} with your compiler of choice. It is up to you (as the user) to ensure that this command matches what you are using in your Makefile.
To change the ${COMMAND}:
Open Project Properties (by right-clicking on the project)
Select C/C++ General -> Preprocessor Include Paths, Macros, etc in the tree.
Select Providers tab
Select CDT GCC Built-in Compiler Settings from the list
Replace the ${COMMAND} in Command to get compiler specs: to your desired g++ executable.
Here is a screenshot to help:
To see this in action, here are some screenshots with and without the change described. On my machine I have /usr/bin/g++ which is version 5.3 and /usr/bin/g++-4.7 which is version 4.7.
With default g++
With overridden g++ to version 4
Use Environment manage
The problem with the above is that you need to coordinate g++ between your Makefile and the build settings. One solution to this is to use the C/C++ Build Environment settings to define CXX as the compiler to use. Set the CXX environment variable in the project settings (Project Properties -> C/C++ Build -> Environment) or global preferences (Preferences -> C/C++ -> Build -> Environment).
Then replace ${COMMAND} with ${CXX}.
Here is a screenshot that demonstrates what I described:
Managed Make
If, instead, you are using Managed Make, you need to override the build settings for the individual tools. These settings then feed into the Preprocessor Include Paths, Macros, etc. settings as used directly by Standard Make.
To change the build settings, you need to override the command used for the compiler in a few places, once for each type of tool. Start in Project Properties -> C/C++ Build -> Settings and then edit each of these:
GCC C++ Compiler -> Normally set to g++
GCC C Compiler -> Normally set to gcc
GCC C++ Linker -> Normally set to g++
Here is a screenshot to demonstrate:

how to use the julia language in c++ (visual studio)

Is it possible to use the julia language in c++?
Does the julia language provides some libraries to include?
For now, I am trying to use some funcitons of the julia language in my c++ project.
Is this possbile? What could I do?
thanks in advance.
Embedding Julia
Yes Julia can be embedded in a C or C++ program on all of the platforms which Julia itself is available and in all cases the general approach is the same, but in particular the embedding in Windows is made harder because currently the framework for compilation/embedding (gcc) is not the default familiar one for that platform (MSVC). The reason is that Julia is built on Windows using gcc rather than MSVC.
High level
At a high level the steps for embedding Julia include compiling using the resources supplied by the Julia distribution (see below) and then initializing the program to start the Julia engine.
include julia.h
All of the necessary defines for either a c or c++ program are located in julia.h. The exact location for it differs for each distribution, but in general it's located in julia-basedir/include.
link to libjulia
Likewise all of the necessary symbols to embed Julia are located in libjulia. On OS/X and Linux libjulia.so will be generally available in julia-basedir/julia/lib while on Windows libjulia.dll will be julia-basedir/julia/bin.
or optionally in 0.4: use julia-config.jl
The previous might all sound confusing, but luckily contained in the newest Julia 0.4 distributions is a script called julia-config.jl which will provide all of the needed compiler flags automatically -- disclaimer I wrote it. In this case all that you need to do is cut and paste and follow the pattern in the documentation, create a Makefile, and make will take care of the rest.
initialize using jl_init
As described in the docs, use jl_init to start the Julia runtime, while optionally specifying the directory where the Julia compiled base support sys.ji can be located. I've found it's best to specify this directly rather than let it default; julia-config.jl also provides -DJL_INIT_DIR which can be blindly used as an argument to jl_init; the docs provides details.
The problem with Windows
Returning to Windows. If you follow the instructions to compiling Julia in Windows, you will end up with an MSYS2 compilation environment. Note that these instructions are somewhat out of date, and MSYS2 has advanced since then, so it is now simpler (for example use of 7-zip is not necessary). As an aside, this also allows you to obtain git directly -- note the last comment by #ntzrmtthihu777 is now the best one as git via MSYS2 superior to git-bash which is based on the older MSYS.
gcc
Now MSYS2 does indeed provide a gcc, but you must not use it because it implicitly uses a threading model (POSIX) that is different from the one used by Julia (Winthreads) and instead you must obtain gcc from mingw-builds which gives you an option to pick the model during the install; this is indicated by the Julia compilation Window README too, but it bears repeating. Other tools can be obtained from the MSYS2 package manager pacman.
Mingw builds provides an installer, and I've found that the following fstab will be sufficient to make the mingw-builds gcc available in the right location:
none / cygdrive binary,posix=0,noacl,user 0 0
c:/mingw-w64/x86_64-4.9.2-win32-seh-rt_v3-rev1/mingw64 /mingw64 ntfs binary,noacl,auto 0 0
Looking beyond
If you are successful creating a compilation environment suitable for compiling Julia from source -- you can verify this by actually compiling Julia -- then the instructions above including the julia-config.jl/Makefile simplification will work, and will produce a program that embeds Julia and will be a .exe that will work even when invoked outside of MSYS2, which is nice.
But if you are looking to use MSVC directly, then I should warn you that compilation of Julia with MSVC is still int the early stages, so the above approach with MSVC substituted for gcc will not work currently, but there is the possibility that libjulia could be linked to; it is expected that libraries created by mingw are usable by MSVC at least.
Updated MSVC Compilation (creating julialib.lib)
libjulia.dll is the library that contains all the symbols necessary to embed Julia, and in addition, though it is created by gcc, it can be used by MSVC because all of those symbols have C naming, and are not C++ name-mangled. However, it's not usable directly, but requires a .lib to be created. Which can be done in the following way.
Create julialib.lib
use dumpbin to export symbols from the dll into a file for example:
dumpbin /exports libjulia.dll > output
transform the output to a .def file by removing the extraneous text and placing EXPORTS at the top of the time as described in detail here
Use lib to create a .lib from the .def.
lib /def:libjulia.def /out:libjulia.lib /machine:x64
Place libjulia.lib in the same directory as libjulia.dll
Build project by including julia.h and link to libjulia.lib
waTeim's answer is correct, go vote for it! I just want to complement it with steps to use the library in your Visual Studio project. The following assumes that libjulia.lib is in your Julia's bin subfolder, and you want a 64 bit application. I did it in Visual Studio 2013.
First setup the 64 bit solution / project if not done already. Select / click / check the following:
Build / Configuration Manager
Active solution platform / New
X64 / Copy settings from Win32 / Create new project platforms
Then setup your project's configuration:
Right click project / Properties
Select Configuration = All Configurations, Platform = x64
Debugging / Environment: PATH=$(JULIA_HOME);$(PATH)
C/C++ / General / Additional Include Directories: $(JULIA_HOME)\..\include\julia
Linker / General / Additional Library Directories: $(JULIA_HOME)
Linker / Input / Additional Dependencies: add libjulia.lib to the list
Ensure your active configuration is for platform x64 then build your solution. It worked for me, hopefully it will work for you as well :)

Programming language that doesn't require a runtime/dependency to be installed

I want to know a programming language that doesn't require a runtime/dependency to be installed on the target system. My primary target is Windows XP and above.
I tried Autohotkey but it dosent have many advance functions.
Firstly, please confirm that does 'C++' requires to install a runtime/dependency on the target system is is Win XP or later. Secondly, please suggest me an alternative to C++ that doesnt require a dependency to be installed.
UPDATE: I will be using CodeBlocks! Does the C++ code compiled with that requires a dependency?
UPDATE: Sorry for the misconception, by CodeBlocks I mean the default compiler of CodeBlocks (ie: GNU GCC Compiler or MinGW).
Everything usually depends on the project, not the language. For example, programs compiled in Visual Studio's C++ uses some runtime libraries to work properly. However, you can configure the project in such way, that these libraries are included in the executable file, thus not needing additional dependencies. Delphi works similarly.
Here's the setting for Visual Studio Project:
If you choose option with "DLL", your program will require runtime DLLs. Otherwise it will be standalone, the runtimes will be incorporated into your binary file.
Edit: In response to question edit
I'll repeat myself: it depends on project, not the compiler or IDE.
If you want to create a program that does not require anything else in order to run, except for base operating system (no .NET, no Java, no Perl, no runtime libraries, etc), then your best bet is to use C or C++ and compile your program as single statically compiled executable.
It is rather difficult to achieve in practice, but it can be done.
Codeblocks is not a compiler, but an IDE, that can use different compilers.
The most common one is MinGW.
To complie with minGW so that all the standard libraries are statically linked you shold configure your project (see "project settings") so the the linker options include the -static flag.
You can even be more specific by stecifying
-static-libgcc
-static-libstdc++

What C++ implementation/library is my IDE using? (NetBeans, MacOSX)

Can anyone tell me how an IDE like NetBeans or any for that matter gather all the standard C++ libraries? For example, I created a new Netbeans C++ application, and included iostream and it worked no problem. However, if I do a search for filename "iostream" on my MacOSX Snow Leapord, it finds it in the path
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/stream
Does that mean that my IDE is using my operating system's C++ library? It's strange because all of these files are "copyright apple" - so I'm assuming that this is a C++ implementation modified by Apple?
I was under the impression that there was 1 standard C++ libary and all compilers used that. Is Netbeans somehow just gathering the same library that Xcode is bundled with?
Essentially, I'd like to view the source of some C++ headers to gather more information about their inner-workings, but I'm worried that I am using some super-heavyweight, Apple-modified core lib that may not even be legal to use because it's under some Apple liscense.
Thanks everyone
NetBeans is just an IDE, it doesn't come with a compiler or any C++ libraries. Since it looks like you already had Xcode installed, NetBeans automatically uses compilers and libraries associated with Xcode. I have no idea what the apple licenses are, but since you bought and own your Mac, I don't think there is a problem using those headers.
Also, to view headers, just right click the code and Go To -> C++ Declaration or Header Files.
There is a place you installed g++, and your include files all come from there.
You can add additional header files by using the gcc -I switch, and that is implemented in Netbeans in the build tool chain option
further information here
I don't have a mac in hand right now, but I guess the include files will be in somewhere like:
/usr/share/g++
EDIT:
You can find the code assistance pop-up include files at:
Tools -> Options -> C/C++ -> Code Assistance

Port GNU C++ programs to Visual C++

How do you port C++ programs with makefile made from GNU C++ in Linux to Visual C++?
One thing I can suggest is to use CMake. If you implement your build system with CMake to auto-generate the makefiles for GCC on Linux, it takes only minor modifications to auto-generate projects and solutions for VC++.
Of course, this means learning a whole new build tool, so it may not be for you. It's only a suggestion.
I don't know about an easy way to simply convert from one to another, but..
Assuming you use only ANSI C/C++ features, usually you don't need to convert the makefile, just look which .c/.cpp files are in it and add them to the VS project; you'll also have to check about compiler options and defined macros, to put them inside the VS project. I've done this to compile libs like expat, freetype, agg and others, without problems.
Porting the build system: You could use a Windows port of GNU make, and change the makefile to invoke the Visual C++ command line tools (cl.exe, link.exe, lib.exe, etc.) when building on Windows and the GNU compiler tools when building on Linux. The difficulty of this approach depends on the complexity of the makefiles.
Porting the code: This depends on what APIs and libraries you are using, and what compiler warnings/errors/quirks you will encounter. For a more specific answer, ask a more specific question.
CMake was mentioned. I have used CMake and successfully compiled the resulting Visual Studio project. I found the CMake documentation very unhelpful -- I had to ask an existing user -- and the official manual (which costs money) was out of print at the time. Further, the Visual Studio project it produced was very rigidly formatted according the template preferred by whoever wrote the converter. I was unable to figure out how to customize project options or group source files.
I regularly cross-compile on Visual Studio and G++. For the most part, you just need to add all of the source files and header files into a Visual Studio project ('Add Existing Files', and add your entire source tree) and then compile it. Usually you'll get errors, so you start fixing bugs from there. If you used platform-specific libraries, you may be stuck porting to an alternative or removing features.
One further word of caution: Visual Studio and G++ have different compiler quirks. For the most part, they both conform excellently to the C++ standard, but slightly off-standard code which works in one may not work in the other. I have found this to be particularly true when dealing with templates, with Visual Studio being bizarrely permissive of syntax errors in many cases.
CMake has the nicety of generating visual studio project.
If you do not need that, I suggest Meson build system. Much nicer, similar proposal. Requires python3 and ninja, but noone is perfect. :)