First Boost program - c++

I have tried to write my first Boost program from information on the Boost libraries site.
Here is the code:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
It shows me this error:
1>------ Build started: Project: boost_librarys, Configuration: Debug Win32 ------
1> boost_librarys.cpp
1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How can this error be fixed?

The answer to a similiar question outside SO was:
Download and install the Windows SDK from here
(link in quote may not be fitting for your system)

Make sure you have the Windows SDK installed.

The link error you're getting means that your program isn't linking to the correct libraries. Since the error refers to a Microsoft system library (kernel.lib), you'll need to make sure you've got your system set up correctly. This isn't a Boost problem per se, although it may be Boost that's interested in linking with kernel.lib.

You are on Visual, there is NO reason why kernel32.lib wouln'd be around. Anyway, it should be in C:/Program Files(x86)/MS Visual Studio/VC/lib
My guess is that you mistyped something in the project's configuration. Every lib, every additional path should be separated by a ';'. If you're unsure, click on the right [...] , in the new window there should be one item by line only.

Related

How does visual studio (ms compiler) know it needs specific boost libraries

vs2015 community, x64, debug, boost 1.63
New Empty project
Properties->C++->General->Additional Include Directories add
"C:\Program Files\boost_1_63_0" Add new C++ file, Source.cpp:
#include "boost/make_shared.hpp"
#include "boost/thread.hpp"
void main(int argc, char **argv)
{
}
Build Solution
Result:
1>------ Build started: Project: boostLibTest, Configuration: Debug x64 ------
1> Source.cpp
1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc140-mt-gd-1_63.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Where is that lib file getting added to the project? It's not boostLibTest.vcxproj, nor the command line for the compiler.
I wanted to write a static library that uses boost that I can access from another app that doesn't have/need boost, but this auto-include-boost-dependency prevents me from doing so.
There are #pragmas that MSVC supports that let a header file state "you need this library".
Boost is apparently using them.
Ideally, boost should only include them in header files that are not "header only". The granularity may not be perfect. But if you only need some enum values and other header-file only data from "boost/thread.hpp", check to see if they are included in a "header-file-only" header.

C++ Error for file_size() which belongs to Boost Filesystem

My IDE is MS Visual Studio C++ 2013, and I use Boost Library for Filesystem Operations.
I have written this code:
// BoostFileSystem.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <boost\filesystem.hpp>
using namespace boost::filesystem;
using namespace std;
int main()
{
cout << "File Size: " << endl;
cout << file_size("as.jpg");
return 0;
}
It throws error. The error is that:
1>------ Build started: Project: BoostFileSystem, Configuration: Debug Win32 ------
1> BoostFileSystem.cpp
1> LINK : C:\...\visual studio 2013\Projects\BoostFileSystem\Debug\BoostFileSystem.exe not found or not built by the last incremental link; performing full link
1> BoostFileSystem.vcxproj -> C:\..\documents\visual studio 2013\Projects\BoostFileSystem\Debug\BoostFileSystem.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
'as.jpg' is also included in the Resources folder. When I remove this line:
file_size("as.jpg");
The error is not thrown. Also bear in mind that the compiler reports no failure.
What is the problem? I really cannot figure it out.
Because when I remove file_size() line, the program works fully and also prints the text on the screen ("File Size:"). While when run it as-is, the compiler throws no error, but no text (even the line before the file_size()) is not printer and in the console the following is printed (which is also outputed to the error-area as already pasted above):
UPDATED:
Here is the error shown in the console window:
The system cannot find the file C:\Users\Ali\do
ts\BoostFileSystem\Debug\BoostFileSystem.exe.
The problem is solved. I post it for future visitors.
The problem is with incremental linking enabled in MS-Visual Studio C++. If disable it, then the program works.
Go to the properties of the project, then to the Linker, General and Disable the Incremental Linking.

OpenCV error: "LINK : fatal error LNK1104: cannot open file 'opencv_core231d.lib' "

I'm trying to compile a simple code in visual studio + opencv, but got this error.
Code:
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main ( int argc, char **argv )
{
Mat im_gray;
Mat img_bw;
Mat img_final;
Mat im_rgb = imread("001.jpg");
cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
adaptiveThreshold(im_gray, img_bw, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 105, 1);
imwrite("001-bw2.jpg", img_final);
return 0;
}
Output:
1>------ Build started: Project: pibiti, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'opencv_core231d.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The Linker >> Input:
opencv_core231d.lib
opencv_highgui231d.lib
opencv_video231d.lib
opencv_ml231d.lib
opencv_legacy231d.lib
opencv_imgproc231d.lib
tbb_debug.lib
tbb_preview_debug.lib
tbbmalloc_debug.lib
tbbmalloc_proxy_debug.lib
tbbproxy_debug.lib
How can I fix this? the file 'opencv_core231d.lib' is already there, why this error?
Add the path of the library files to the library path.
Right click the project and go to Properties->Linker->Additional Library directories. Add the path to this list.
Adding to this list of solutions, mine was simply to change the project to 64 bit.
I had the same issue. Despite ensuring that the path to the libraries was correct, I was getting a "Cannot open file" error. The issue was I had named the dlls wrong in additional assembly references in Linker Properties. I had given them as above(with "231" at end). But the names of the actual Dlls were ending with "249". Changing that solved my issue. Might be helpful to others :-)
After this, project will get built successfully. But you can expect a run time error that opencv_core249d.lib is missing in your computer, you need to re-install it. That is becuase even though the path has been added to environment variables, windows has to be restarted to have it in effect. This will solve it.
I had same problem so in Properties->Linker->Additional Library directories,
I had to replace
$(OPENCV_DIR)\lib
with
C:\opencv\build\x86\vc12\lib
both in debug and release.
And now it works.
I had a similar issue - I solved it by changing the link in the path.
Instead of: $(OPENCV_DIR)\lib or this kind of path C:\opencv\build\x86\vc12\lib just add \ at the end.
For me it worked with C:\opencv\build\x86\vc12\lib\ so I didn't try with the environment variable.

playing a .wav file

I'm using visual studio 2010 express and I'm trying to write a simple program that will repeat a wave file 5 times(I'm running a windows xp sp3).
This is as far as I got:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
int main ()
{
int a = 5;
while(a >= 1){
cout << "It's a wav file";
PlaySound(L"SomeAudioFile-01.wav", NULL, SND_FILENAME);
--a;
}
return 0;
}
The problem is I keep getting this error message when I'm building it:
1>------ Build started: Project: It's a F**king Country, Configuration: Release Win32 -- ----
1> mycode.cpp
1>..\..\..\..\..\Shaul's documents\Visual Studio 2010\Projects\MyProject\Release\SomeAudioFile-01.wav : fatal error LNK1136: invalid or corrupt file
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The file is perfectly fine and plays with no problems whatsoever outside visual studio.
Help would be truly appreciated.
Instead of adding the WAV file to the project files, add it to the resources and use SND_RESOURCE instead of SND_FILENAME.
You include the sound file as a object file, so the compiler tries to link with it. But it's a binary file that's not linkable (which is what the error message says).
Don't include the sound file in the project, so the environment won't link with it.
P.S. In the future, please refrain from using "bad" words on a public site like this.
To get rid of the linker error, you need to tell the IDE to link with the winmm.lib library also, so open Project/Properties/Configuration Properties/Linker/Input and append winmm.lib in the Additional Dependencies field.
Also, use the following function profile:
PlaySound(L"audio.wav", NULL, SND_APPLICATION);

Cannot open include file X11/X.h when compiling

I've copied the FL folder into the project.
and it show me this:
1>------ Build started: Project: Client, Configuration: Debug Win32
------ 1> Main.cpp 1>c:\users\user\documents\visual studio 2012\projects\talktome\talktome\fl\xutf8.h(33): fatal error C1083:
Cannot open include file: 'X11/X.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
my source code is
using namespace std;
#include "FL\Fl.H"
#include "FL\Fl_Window.H"
#define WIDTH 700
#define HEIGHT 500
int main()
{
Fl_Window win(WIDTH, HEIGHT, "TalkToMe");
win.begin();
win.end();
win.show();
return Fl::run();
}
You should check if there is "#define WIN32" before your FLTK includes. will help you. It should. Simular problem here:
FLTK in MSVC needs x11 headers?
Do not use the \ in the include statements. Use the forward slash / .
The problems you refer to in your comment to Mycotoxin clearly indicate you have linking problems. You have to tell your compiler where to find the fltk library and the header files. Unresolved external symbols mean only one thing you know... :)
You do not have to define WIN32 as described in Mycotoxin's text. The compiler does that for you, and FLTK uses this fact. Even if it does not, you typically give it as a parameter to the compiler (something like -DWIN32 in the case of GCC or similar for CL).
Watch Greg's video tutorial at http://seriss.com/people/erco/fltk-videos/ where he explains how to configure FLTK and build a small app using Microsoft Visual Studio 7.
Finally, get the source package, and read the README.MSWindows.txt file. It explains everything you need to know in order to build your FLTK-based application on Windows.