How to include wx in my c++ code (MSVS 2019) - c++

I want to include the wx library in my c++ program but following the given default instruction don't include the library in Visual Studio 2019
I tried (quoting from the instruction install.md):
Open a "Visual Studio Command Prompt"
Change directory to \%WXWIN\%\build\msw and type
> nmake /f makefile.vc
Also i tried to include the file wxwidgets.props as explained in the given instruction
If i try to do
#include <wx/frame.h>
is marked as mistake ("impossible to open "wx/frame.h" of origin file)
Note: for the creation of the GUI I'm also using wxFormBuilder

It's generally a good idea to read documentation when trying to use new software. In this case, the relevant documentation is in the file docs/msw/install.md (or install.txt in earlier wxWidgets versions) and its "Building Applications Using wxWidgets" section contains the information that you need.

After some time wondering around forum, I've found a video on Youtube explaining how to include wx in your Visual Studio project, so i decided to post the answer to my question helping how will need this help in the future like i needed.
First of all you need to open in the Wx Directory and go to wxWidgets-X.X.X\build\msw and open with Visual Studio wx_vc15.sln (or more recent if available)
Compiling the solution in Debug, DebugDLL, Relase and RelaseDLL.
Now open your project (new or old) and open the Project menu and tap Project propriety
Select configuration All configuration, go to section C/C++ and in Additional Include directorys add \wxWidgets-X.X.X\include
Next go under Preprocessor and add in Processor definition the string WXUSINGDLL
Go under Linker and on Additional library Directory add \wxWidgets-X.X.X\lib\vc_dll
Change configuration to debug and under C\C++ add another additional include directory that is wxWidgets-X.X.X\lib\vc_dll\mswud
Finally, as step 7, change to relase and add wxWidgets-X.X.X\lib\vc_dll\mswu
This will include the wx library in your code
Here the link for the video https://www.youtube.com/watch?v=EI2taYkErRg if you need more detail or if you need visually the explaination.
NOTE: in the install.md is missing the part of including the library in the project in this way, it mention only to compile the Debug version not well explaining why or what to do next.

Related

IntelliSense cannot open source file

I started working as a research fellow at my university and was instructed to develop a component for an already existing application written in C++ using an in-house framework, also developed in C++.
Currently I am struggling with properly setting up the project in Visual Studio 2017.
Whenever I try to include a file from the framework, IntelliSense complains about not being able to open the file.
However, following things add to the oddness of the problem:
The solutions properties are set correctly; the project DOES build without any complaints.
Writing the '#include'-directive, IntelliSense DOES suggest the correct relative path to the header files (i.e. #include <framework/class.h>).
I can open the header file from within the source file referencing it, using the 'Open Document "class.h"' dialog.
I have already came across this:
IntelliSense: Cannot open source file in include path
Intellisense cannot open source file "*.h"
So far, nothing solved my issue. Did someone come across this issue yet?
TL;DR
Everything compiles fine.
"C/C++ -> General -> Additional Include Directories" is set properly.
"VC++ Directories -> Include Directories" is set as well.
IntelliSense properly suggests header file, when writing include directive.
BUT IntelliSense reportedly fails to open the file, thus not indexing it.
I am stuck with a fancy but resource hungry text editor.
EDIT:
I am working on a MacBook "13 2016; installed Windows 10 Pro 64-bit via Bootcamp.
This issue occurs because Windows now has the option for making folders case-sensitive and intellisense has a habit of changing the case of files that it tries to open.
Intellisense tries to use a path like C:\WORKSPACEPATH\PROJECTDIR\MYFILE.cpp (i.e. all uppercase), but if C:\workspace (or any of the other directories in the path) are set to be case-sensitive and don't exactly match, it won't be found.
In my case it was because I created the folder via WSL which enables case sensitivity by default on any new directories it creates (including via things like git clone). See here
Easy Fix
This can be fixed by running the following:
fsutil file setCaseSensitiveInfo <directory> disable
More Commands
You can check whether a folder has case sensitivity enabled by running
fsutil file queryCaseSensitiveInfo <directory>
and Finally, a handy one-liner to disable this recursively:
for /r /d %f in (.) do (fsutil file setCaseSensitiveInfo %f disable)
(This info was originally posted as a comment to the original question, before it turned out it was in fact the same problem. See the comments for input from a couple of other people)
For a Linux project open in Visual Studio 2022, I tried the accepted answer from #yothsoggoth, , which makes sense to me, but unfortunately didn't work.
I realized that visual studio couldn't even open the C++ file from the standard library using F12 but it could open others from other libraries.
So in my case the solution was to close visual studio, backup the folder working as a cache.
C:\Users\[user]\AppData\Local\Microsoft\Linux to C:\Users\[user]\AppData\Local\Microsoft\Linux.bak
Then I reopened Visual Studio and let CMake to regenerate the cache.
The errors now are gone and I can now even open <string> and others from the C++ std library with F12.
I hope this workaround helps others

Install pdcurses on Visual Studio 2017

I was making a 2048 game on Code::Blocks, but due to debugging problems, I move to Visual Studio Community 2017. It seems that conio.h doesn't work there, so I'm trying to switch to curses.h library.
I've read a lot of tutorials, but none of them worked for me. I visited their website and downloaded the .zip file with 384 kilobytes (KB), but I do not know what to do with these files.
Help, please?
I have found a very useful website which talks about PDCurses and its installation in Visual Studio. Even though it is for 2010/2013, it really worked for me in VS2017 — even the demo programs (with very minute changes)!
So here is the steps I did (since you already have PDCurses):
Take the developer command prompt of VS2017 community edition and type
in set PDCURSES_SRCDIR=<PDCurses Directory Location>; in my case it
was
set PDCURSES_SRCDIR=C:\pdcurses-master
Note: Here we are setting up the environment variable needed for compilation. If you need additional functionality defined by the pdcurses library, you may want to set corresponding variables in this step. For example, if you need wide character support, you can use set WIDE=1. To see what all are the options available, you can open up the make file (mentioned in next step) in any text editor and look for if conditionals.
Navigate in the command window to the directory of PDCurses/win32 (in my case C:\pdcurses-master\win32)
nmake –f vcwin32.mak
(This is the make file for PDCurses.) It will create the pdcurses.lib for our Visual Studio.
Now we need to incorporate the generated library into our project. So open up your project and go to project properties
In “VC++ Directories”, change:
Include directories: Add a new file-path to PDCurses installation directory, in my case it is C:\pdcurses-master.
Library directories: Add a new file-path to PDCurses installation library directory, in my case it is C:\pdcurses-master\win32.
In C/C++:
In “Code Generation” tab, change “Runtime Library” to “Multithreaded Debug (/MTd)”. (Usually, it is set already)
In Linker:
In “Input” tab, add pdcurses.lib to Additional Dependencies (I initially got confused - remember, it is the input tab of linker)
Click on Apply, and OK.
Then wow! I ran some sample programs (demos) from the pdcurses project and all of them worked for me with very slight modifications.
Note: I created a Windows (also known as Win32, as in Win32 API) console application with Visual Studio 2017 and loaded the project. I did include stdafx.h and compilation was successful and I was able to see the output in the terminal window.
The above website also provides a PDF document too. The instruction there starts from the downloading the pdcurses from website.
This is old news now, but it might help somebody to know that pdcurses is packaged up on vcpkg.
To use it, (assuming you have vcpkg installed, of course, (Installing vcpkg) )
vcpkg install pdcurses
and you're off to the races. vcpkg will take care of making sure the include and library paths are all set.

Library installation using compiler

I have been writing C++ code snippets sporadically to speed things up in R via Rcpp, but now I would like to do more using Armadillo library, but I am having trouble installing it.
The README file instructs to create a location for "include" folder and tell your compiler to use that location for header files (in addition to the locations it uses already).
If I save the "include" folder into C:\Users\me\Documents\ARMADILLO, then how do I instruct the compiler to use the appropriate location?
After some search, I tries typing into command line the following (after prompt: C:\Users\me>):
g++ Documents\ARMADILLO\include, but it did not work ("permission denied"). I hence wonder how this should be done.
Moreover, the README file finally instructs to: Configure your compiler to link with LAPACK and BLAS - I would very much appreciate an advice how this should be done as well.
Thanks a lot!
PS: I have Windows 7 and VS Express 2013 for Desktop.
Visual Studio uses solutions which are containers of projects. Each project has a settings page (right click the project in the Solution Explorer window). Under "Configuration properties" there's a VC++ Directories page, which in turn lists "Include Directories". Append ;C:\Users\me\Documents\ARMADILLO
BTW, I find it useful to put such libs under C:\libs\. Saves on path length.

unable to compile examples in ODEINT package

I am trying to solve a coupled set of ODE's in C++, and I have decided that I want to try out odeint (available here) as I have read many good things about it. However I am having compiling the examples that are included in the package. Here is the situation:
So far I have only downloaded the package and extracted it. I am running Visual C++ 6 on Windows XP and I am compiling the example "simple1d". I get the error message: "Cannot open include file: 'boost/config.hpp': No such file or directory".
It is not clear to me what I am missing. Do I need the full boost library to make this work? I was under the impression that ODEINT is a "standalone" package.
Your error says that compiler can not find the boost libraries. You should download them from boost.org and also add them to your header path.
Where did you download and extract the package to? The package homepage says that it's a header-only package, so you only need to let Visual find the header files. I haven't used Visual in a while, but a quick google of something like "Visual 6 add header path" should be a good place to start. Take a look at Where does Visual Studio look for C++ header files?.
Quoting from this page:
Within Visual Studio, go to the Project Settings dialog. We want to change the settings for both Debug and Release versions, so under the Settings For field, select "All Configurations". Under the C/C++ Tab, select Preprocessor options.
The package tarball has a directory called boost: you want to add the path of that directory into the Additional include directories box and then #include <boost/numeric/odeint/config.hpp> in your code.
Update
It appears, then, that you already have the odeint headers installed properly: the file boost/numeric/odeint/config.hpp has a line #include <boost/config.hpp>, which is what visual must be complaining about; so I guess the package is not standalone. It must need other boost header files installed. I can't find anything in either the package homepage or the package tarball that mentions any dependencies, so I suppose you should try to install boost too. Download version 1.51.0 here, and this is the windows documentation.
You must download odeint from http://headmyshoulder.github.io/odeint-v2/downloads.html and Boost c++ libraries from http://www.boost.org/users/history/version_1_51_0.html.
If you use codeblocks right click your project, select build oprions, select Search Directories and add two references one for odeint and one for boost.

How do I start a new CUDA project in Visual Studio 2008?

This is an incredibly basic question, but how do I start a new CUDA project in Visual Studio 2008? I have found tons and tons of documentation about CUDA related matters, but nothing about how to start a new project. I am working with Windows 7 x64 Visual Studio 2008 C++. I would really like to find some sort of really really basic Hello World app to just get a basic program compiling and running.
Edit:
I tried your steps Tom. I setup a console app. I then deleted the default .cpp it drops in and copied over the three files from the template project just to have something to compile. When I compile that, template_gold.cpp complained about not having stdafx.h included, so i included that. Now the build fails with this:
1>------ Build started: Project: CUDASandbox, Configuration: Debug x64 ------
1>Compiling...
1>template_gold.cpp
1>Linking...
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
1>D:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\x64\Debug\CUDASandbox.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://d:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\CUDASandbox\x64\Debug\BuildLog.htm"
1>CUDASandbox - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
NOTE With the release of version 3.2 of the CUDA Toolkit, NVIDIA now includes the rules file with the Toolkit as opposed to the SDK. Therefore I've split this answer into two halves, use the correct instructions for your version of the Toolkit.
NOTE These instructions are valid for Visual Studio 2005 and 2008. For Visual Studio 2010 see this answer.
CUDA TOOLKIT 3.2 and later
I recommend using the NvCudaRuntimeApi.rules file (or NvCudaDriverApi.rules if using the driver API) provided by NVIDIA, this is released with the toolkit and supports the latest compiler flags in a friendly manner. Personally I would advise against using the VS wizard, but only because I really don't think you need it.
The rules file (installed into the Program Files\Microsoft Visual Studio 9.0\VC\VCProjectDefaults directory) "teaches" Visual Studio how to compile and link any .cu files in your project into your application.
Create a new project using the standard MS wizards (e.g. an empty console project)
Implement your host (serial) code in .c or .cpp files
Implement your wrappers and kernels in .cu files
Add the NvCudaRuntimeApi.rules (right click on the project, Custom Build Rules, tick the relevant box), see note 1
Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> General add $(CUDA_PATH)\lib\$(PlatformName) to the Additional Library Directories and in Linker -> Input add cudart.lib to the Additional Dependencies), see notes [2] and [3]
Optionally add the CUDA include files to the search path, required if you include any CUDA files in your .cpp files (as opposed to .cu files) (right click on the project and choose Properties, then in C/C++ -> General add $(CUDA_PATH)\include to the Additional Include Directories), see note [3]
Then just build your project and the .cu files will be compiled to .obj and added to the link automatically
Some other tips:
Change the code generation to use statically loaded C runtime to match the CUDA runtime; right click on the project and choose Properties, then in C/C++ -> Code Generation change the Runtime Library to /MT (or /MTd for debug, in which case you will need to mirror this in Runtime API -> Host -> Runtime Library), see note [4]
Enable syntax highlighting using the usertype.dat file included with the SDK, see the readme.txt in <sdk_install_dir>\C\doc\syntax_highlighting\visual_studio_8
I'd also recommend enabling Intellisense support with the following registry entry (replace 9.0 with 8.0 for VS2005 instead of VS2008):
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Languages\Language Services\C/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"
Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
CUDA TOOLKIT 3.1 and earlier
I would use the Cuda.rules file provided by NVIDIA with the SDK, this is released alongside the toolkit and supports the latest compiler flags in a friendly manner. Personally I would advise against using the VS wizard, but only because I really don't think you need it.
The rules file (in the C\common directory of the SDK) "teaches" Visual Studio how to compile and link any .cu files in your project into your application.
Create a new project using the standard MS wizards (e.g. an empty console project)
Implement your host (serial) code in .c or .cpp files
Implement your wrappers and kernels in .cu files
Add the Cuda.rules (right click on the project, Custom Build Rules, browse for the rules file and ensure it is ticked)
Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> General add $(CUDA_LIB_PATH) to the Additional Library Directories and in Linker -> Input add cudart.lib to the Additional Dependencies), see note [2] below
Optionally add the CUDA include files to the search path, required if you include any CUDA files in your .cpp files (as opposed to .cu files) (right click on the project and choose Properties, then in C/C++ -> General add $(CUDA_INC_PATH) to the Additional Include Directories)
Then just build your project and the .cu files will be compiled to .obj and added to the link automatically
Some other tips:
Change the code generation to use statically loaded C runtime to match the CUDA runtime, right click on the project and choose Properties, then in C/C++ -> Code Generation change the Runtime Library to /MT (or /MTd for debug, in which case you will need to mirror this in CUDA Build Rule -> Hybrid CUDA/C++ Options), see note [4]
Enable syntax highlighting using the usertype.dat file included with the SDK, see the readme.txt in <sdk_install_dir>\C\doc\syntax_highlighting\visual_studio_8
I'd also recommend enabling Intellisense support with the following registry entry (replace 9.0 with 8.0 for VS2005 instead of VS2008):
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Languages\Language Services\C/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"
Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
NOTE
You can also use a Toolkit-version-specific rules fule e.g. NvCudaRuntimeApi.v3.2.rules. This means that instead of looking for the CUDA Toolkit in %CUDA_PATH% it will look in %CUDA_PATH_V3_2%, which in turn means that you can have multiple versions of the CUDA Toolkit installed on your system and different projects can target different versions. See also note [3].
The rules file cannot modify the C/C++ compilation and linker settings, since it is simply adding compilation settings for the CUDA code. Therefore you need to do this step manually. Remember to do it for all configurations!
If you want to stabilise on a specific CUDA Toolkit version then you should replace CUDA_PATH with CUDA_PATH_V3_2. See also note 1.
Having mismatched version of the C runtime can cause a variety of problems; in particular if you have any errors regarding LIBCMT (e.g. LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs) or multiply defined symbols for standard library functions, then this should be your first suspect.
What a great question!! For all the CUDA documentation out there, this is something that I've always thought was an obvious omission... In fact, I'm really glad I found this post, because after using CUDA for quite a while, I still hadn't found an official, correct way to get VS to produce a CUDA program from scratch.
When I've needed to start a new CUDA program, I've always just copied and modified the "template" example from the SDK directory. This may not be exactly what you're looking for, because it doesn't start fresh, but it is a quick way to get a CUDA-capable project working in VS with all the correct project/file names...
Make a copy of the "template" example from the SDK, and rename the directory -- the only necessary contents in the directory are source code and VS .sln and .vcproj files
Rename both .sln and .vcproj files
Open the .sln file in a text editor, and rename the Project variable and .vcproj filename in the 3rd line of the file
Open the .vcproj file in a text editor, and rename the Name and RootNamespace variables in the first few lines of the file
Open the project with VS, and open the Property Pages (right click on the project name in the solution explorer pane, select "Properties")
Change the Output File name in the Property Pages (under Configuration Properties -> Linker -> General) ... Before I change the filename, I select "All Configurations" from the Configuration pull-down and "x64" from the Platform pull-down, since I'm on a 64-bit system
Change the Program Database File name in the Property Pages (under Configuration Properties -> Linker -> Debugging) ... Before I change the filename, I select "Debug" and "x64" in the pull-downs.
Install CUDA VS wizard. It will setup VS and add CUDA Project to the "new project" menu.
Make sure that you have x64 compiler installed (must be checked during VS install).
Check if you have x64 libs, includes, nvcc dir and in the search path.
Create new project using CUDA template.
Change project type to x64 and CUDA setting to Native (if you have nv cuda-enabled card) or emulation otherwise.
The template will create custom build rules that compile .cu files with nvcc and other files with default compiler.
if, vs is trying to compile .cu files with C/C++ compiler, click on that file in solution explorer and disable compilation for that files (red dot on file's icon)
Additional info about installing CUDA wizard on VS2008 can be found here and here
[edit]
If you don't want to use wizard you have to setup CUDA lib/include/nvcc paths manually and add custom build rules to each new CUDA program. For additional info how to do it take a look at Tom's Answer.
You may want to take a look at this guide: http://www.programmerfish.com/how-to-run-cuda-on-visual-studio-2008-vs08/