I have used OpenMP with gcc for writing parallel code. I am now using Visual C++ 2005 and am trying to figure out how to use OpenMP. There is a compiler option in the Properties->C/C++/Language menu but then it complains the library is missing. Is there a 3rd party implementation for OpenMP or am i just configuring Visual C++ incorrectly?
After some research I found out that the OpenMP libs and dlls are not included with Visual C++ 2005 or Visual C++ Express Edition 2008. But with a few workarounds you can get it working.
First you need to download the lib files from microsoft which can be found at the Windows SDK for Windows Server 2008 and .NET framework 3.5. After you download it you need to make sure that either vcomp.lib or vcompd.lib is being linked to your program.
Next you need to have the dll which can be found in the Visual C++ Redistributable Packkage. Then make sure that vcomp90.dll is somewhere in your path.
You also need to have the OpenMP compiler option enabled which can be found in the Properties->C/C++/Language menu of Visual C++.
After that you should be able to use OpenMP just fine.
I think t works out of the box with VC 2005 but I am not sure if they are provided with all versions.
If you jsut attach the
/openmp
option you also have to include the open mp header
#include <omp.h>
This is important because this header will add the manifest to your application which
enables it to load the vcomp.dll from the correct system path. So it is normally no longer
allowed to copy vcomp.dll or other system dlls beneath your executable but you have to pimp the manifest of your application to load the dll from the correct location.
This is none automatically by the omp.h header.
So the minimum code if you do not want to modyfy your manifest on your own is:
#include <omp.h> // has to include this header to build the correct manifest to find vcom.dll or vcompd.dll
int main(int argc, char* argv[])
{
double sum;
#pragma omp parallel for
for(int i = 0; i < 10000; ++i) {
}
return 0;
}
You need to add:
/openmp
To your compiler options.
More information is available on MSDN
Related
I am trying libvips for visual studio 2012, starting with a simple example at
http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/vipsmanual/vipsmanualse1.html#x6-60001.1.1
#include <iostream>
#include <vips/vips>
int
main (int argc, char ⋆⋆argv)
{
if (argc != 3)
{
std::cerr << "usage: " << argv[0] << " infile outfile\n";
return (1);
}
try
{
vips::VImage fred (argv[1]);
fred.invert ().write (argv[2]);
}
catch (vips::VError e)
{
e.perror (argv[0]);
}
return (0);
}
What I did was:
Download and extract libvips at http://www.vips.ecs.soton.ac.uk/supported/7.34/win32/
Add to VC++ Directories->Include directories as vips-dev-7.34.1\include (vips-dev-7.34.1 is the extracted folder)
Add to VC++ Directories->Library directories as vips-dev-7.34.1\lib
Add a system path entry as vips-dev-7.34.1\bin
Basically because there are not much guide on using libvips with visual studio, so I applied the procedure that I used for OpenCV. The guide only say "All you need to do is include . This will get all of the include you need". Aparrently there are much more than that.
Upon building, the first error is "Unable to find header file "glib-object.h". Essentially, vips/vips call glib-objects "include which lies inside a subfolder of include \include\glib-2.0\glib-objects.h. I searched for a way to make VS search for all subfolders within the main include folder, it seems that such "recursive search" is not possible in VS. One has to point exactly to the folder containing header file and I may need to add all of the subfolders manually. So I tried adding vips-dev-7.34.1\include\glib-2.0 to VC++ Directories->Include directories. But then glib-objects.h calls for another glibconfig.h which is nowhere to be found within the include folder and subfolders.
Have someone sucessfully make libvips work with VS? Can you give me some advices if I miss something.
I'm the libvips maintainer. Sorry, it's very difficult to use the pre-built libvips binaries with VS, for various reasons (see below). I think your options are to use mingw instead, to cross-compile from linux (this is what I do), or to rebuild libvips yourself from source using VS (perhaps a week's work for an experienced dev?). There are some notes on the vips website about this issue.
The libvips.dll on the website has been cross-compiled from linux using mingw. It's set up for a linux-style build system with pkg-config, so you will have a lot of compiler flags to figure out in VS, and it's built against msvcrt.dll, the Windows C runtime, rather than msvcrtXX.dll, the VS runtime, so you will have endless annoying compatibility problems unless you also build against the Windows runtime.
Unfortunately VS no longer supports building against the Windows runtime. They have an internal tool which does support this mode, but it's not publicly available. I read somewhere you can coax the DDK compiler into doing this, but it's also not supported.
CoApp is an interesting project (partly supported by Microsoft) that is attempting to make building software on Windows less painful, but it's still in beta. You could maybe ask if they have a libvips packaged up for VS, or are considering making one.
I tried to use Microsoft Visual Studio 2012 Express to auto parallelize a "for" loop in Win 32 bit and x64 bit settings. Command line options were set to /O2 /Qpar /Qpar-report:2 to enable optimization, auto parallelization, and reporting of successful and failed "for" loop auto-parallelization. 32 to 64 bit settings were changed via the method used here: ( http://msdn.microsoft.com/en-us/library/vstudio/9yb4317s.aspx ). A 64 bit version of Windows is running on my computer. The sample code I used came from here: (http://msdn.microsoft.com/en-us/library/hh872235.aspx). The code I ran was as follows:
int A[1000];
void test()
{
___#pragma loop(hint_parallel(0))
___for (int i=0; i<1000; ++i)
___{
______A[i] = A[i] + 1;
___}
___for (int i=1000; i<2000; ++i)
___{
______A[i] = A[i] + 1;
___}
}
int main()
{
___test();
___return 0;
}
Building with Win32, I yield this reporting output:
--- Analyzing function: void __cdecl test(void)
d:\myproject\mytest.cpp(4) : loop parallelized
d:\myproject\mytest.cpp(4) : loop not parallelized due to reason '1008'
Building with x64, I did not yield any reports of "loop parallelized" or "loop not parallelized".
Why were there no reports? Is it because I only have visual studio 2012 express, but I needed VS 2012 professional? Does this happen to all computers or across all version of VS 2012? How do I fix this problem so that I will have auto-parallelization reporting ( /Qpar-report:2 ) on with a 64 bit Microsoft Visual Studios project?
/Qpar-report works well in x64 compilation mode in the retail edition. Express doesn't use a special build of the compiler.
A possible explanation is that you forgot to also set the /Qpar-report option for your x64 configuration. These settings are saved per configuration. Right-click your project, Properties. Check the combo boxes at the top of the dialog. Ensure that you've got the proper Configuration and Platform selected.
And make sure you do this for the Release build, the Debug build doesn't parallelize these loops.
I am porting a C++ project from an old Borland compiler to VisualStudio 2008. This project uses a third party DLL that I don't have the source code for, so I am unable to recompile or modify it. The header file for the DLL defines functions along the lines of:
extern "C" {
void __stdcall Init(int a, int b);
}
However when I try to link to this DLL, VisualStudio says that it cannot find the function _Init#8. When I look at the DLL I find that the function name is _Init, and not _Init#8 (it seems that the DLL to predates Microsoft adding #8 to stdcall name mangling).
My question is: How can I call funcions in this DLL? Does VisualStudio simply not support these old DLLs, or is there a flag/setting that I'm missing. (I am aware that I could use the LoadLibrary/GetProcAddress functions to dynamically call the functions at run-time, but would prefer to not to.)
I didn't notice anything that would tell me whether you are doing 32 or 64 bit coding. MSDN has some information on how to create an import library based on a dll that you have no source for. This article is for making a 32 bit import library. CHEERS!
I need my application to be upgraded from visual studio 2005 IDE to visual studio 2012 .
The upgradation wizard converts the solution and project files successfully with 0 errors and few warnings.
But when i start building the application i get error message :
error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended. in atlcore.h !
I tried changing the version no to 0x0500 , 0x0501 , 0x0502 and also 0x0601 ( both through /D compiler option and manually changing in atlcore.h , WINVER is also changed. ) but no luck . the same error is being displayed.
Where do i go wrong ?
Visual C++ no longer supports targeting Windows 95, Windows 98, Windows ME, or Windows NT. If your WINVER or _WIN32_WINNT macros are assigned to one of these versions of Windows, you must modify the macros.
To modify the macros, in a header file, add the following lines.
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
EDIT:
WINVER determines the minimum platform SDK required to build your application, which in turn will determine at compile time which routines are found by the headers.
#define _WIN32_WINNT_NT4 0x0400
#define _WIN32_WINNT_WIN2K 0x0500
#define _WIN32_WINNT_WINXP 0x0501
#define _WIN32_WINNT_WS03 0x0502
#define _WIN32_WINNT_WIN6 0x0600
#define _WIN32_WINNT_VISTA 0x0600
#define _WIN32_WINNT_WS08 0x0600
#define _WIN32_WINNT_LONGHORN 0x0600
#define _WIN32_WINNT_WIN7 0x0601
Other Solution:
If you have installed a WIndows SDK on your PC (in /Microsoft SDKs/Windows), you can #include in stdafx.h (or in a header you include in all your C++ files). Including SDKDDKVer.h will target the highest Windows version available.
Hopefully It work!!!!!
For more info SEE HERE
Problem temporarily solved by commenting a check in atlcore.h :
if _WIN32_WINNT > 0x0501
//#error This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
endif
I know it isnt the right way to do [ editing a file shipped by the IDE ] but did since it may be due to Improper installation.
If anyone come across a permanent fix let me know .
you can add a pre-processor directive for the project under project settings, C/C++, Pre-processor definitions, appending WINVER=0x0501;
(you can also undefine definitions)
I'm wondering if you are using pre-compiled headers which is overwriting changes to stdafx.h, this is the way to make sure this is set
This preprocessor setting holds until code in the project files changes it, at which point if this doesn't fix the problem, then you must find how or where this is being set/unset/checked; but the solutions shouldn't involve any changes to the windows SDK files
I am teaching myself how to read in wav files into C++ as a part of me learning C++. I have found many resources online that recommended the following library: libsnfile library
So I followed some tutorials below in testing the basic functionality of the library, but I can't get the library to compile with Visual Studio 2010.
I have searched online for the following error, but did not find anything useful for my particular error. I downloaded the libsndfile C++ windows installer found here. I used the 32bit version since I am using the win32 C++ console version. However, my Visual Studio is 64 bit. I did the following after I downloaded the installer:
I went into Visual Studio. Under my project, I did the following:
In project properties:
1. VC++
Include >> added ...\libsnfile\include
Library >> added ...\libsnfile\lib
2. C\C++
Added the following directory as additional dependencies
...\libsnfile\lib\libsndfile-1.lib
I did this to add this third party library to my project. After this, to test, I ran the following code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("This is a test\n");
getchar();
return 0;
}
I coded that to make sure that I could access the sndfile.h in my program and everything compiled. The problem occured when I tried to implement the following code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("This is a test\n");
//This will be the length of the buffer used to hold samples while the program processes them.
//A SNDFILE is like FILE in a standard C library. Consequently, the sf_open_read and sf_open_write functions will return an
//SNDFILE* pointer when they successfully open the specified file.
SNDFILE* sf = NULL;
/*SF_INFO will obtain information of the file we wish to load into our program. */
SF_INFO info;
/*This is where the program will open the WAV file */
info.format = 0;
sf = sf_open("C:\Users\GeekyOmega\Desktop\gameon.wav", SFM_READ, &info);
if(sf == NULL)
{
printf("Failed to open the file.\n");
exit(-1);
}
getchar();
return 0;
}
I then get a system error when I click run inside visual studio when I try to run my program. It says,
The program can't start because libsnfile-1.dll is missing from your computer.
Try reinstalling the program to fix this problem.`
I tried the 64 bit windows installer and tried that, but it didn't work. Anyone understand what I am doing run? I am running Visual Studio's 2010 on Windows 7 as my dev environment.
I apologize if I am making a silly mistake, but I would deeply appreciate if anyone could help me. I tried a few hacky fixes, as I talked about above, but nothing has worked.
EDIT: I am also aware of this thread here, but this doesn't make any sense to my current issue as I am not doing any of this path stuff that they are talking about.
Warm Regards,
GeekyOmega
I fixed the issue. For future readers, this is a very common problem, I think. I placed the .dll in the debug folder of my Visual Studio project. Visual Studio couldn't see the .dll file otherwise. After this, the program fired up as expected and ran. If this does not fix the issue for you, then I suggest something else could be going on.