Can't run simple Visual Studio 2013 project - c++

I was trying to install OpenCV 2411 in Visual Studio 2013, but i receive an error when I try to build the project. The error says: LINK1104: cant open file opencv_core2411.obj
I then decided to check that if I created a simple C++ example without the OpenCV 2411 library and see if i will receive an output. I created a new project to print only the word 'hello', but upon building the project I received the same error message mentioned before: LINK1104: cant open file opencv_core2411.obj despite for that new project that should display 'Hello'; I have not imported the Opencv 2411 libraries.
Why am I receiving that error while the project is never relevant to OpenCV 2411 library?

Try the following steps:
Close and reopen Visual Studio.
Select File -> New Project -> Visual C++ -> Empty Project
Right click source files and select -> Add -> New Item...
Select C++ File (.cpp) and give it a name, i.e. main.cpp
Paste in the "Hello" code (at the bottom of answer)
Press F5 to Start Debugging
Hello Code:
#include <iostream>
int main(){ std::cout << "Hello" << std::endl; return 0; }

Related

LINK : fatal error LNK1181: cannot open input file 'opencv_world341d.lib'

I have found two similar questions this and this .
But they both use opencv, and opencv indeed provide the corresponding lib. I don't use opencv, and my project is very simple, just hello world.I have changed project default configuration like this
except for these configurations, others all take defaults
I just want to test my project configuration,that works find for win32 debug and release. But not work for x64 debug and release, they all tell me LINK : fatal error LNK1104: cannot open file 'opencv_world341d.lib'
I indeed know my project does not use any opencv lib, but why they tell me I need to use opencv_world341d.lib
my code
#include<iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
}
Thanks for everyone who comments on the question. I have solved the problem, although this problem not relevant to OpenCV to much, but I think the solution to the problem may be helpful to others. When I build project, visual studio 2019 tell me cannot link opencv_world341d.lib, so I go to Project->Properties->Linker->Input->Additional Dependencies , and I found opencv_world341d.lib. So I need to remove it, but it's readonly. From this we know visual studio using settings file (Microsoft.cpp..users.props) to control global settings including Global search path. These files are located at $(USERPROFILE)\appdata\local\microsoft\msbuild\v4.0 directory. Then I reedit Microsoft.cpp.<Platform>.users.props, delete opencv_world341d.lib, reboot visual studio, problem solved.

Disabling Auto-generated comments in Visual Studio Enterprise 2017

I would like to disable auto generated comments of Visual Studio every time I create new project. Sample template of visual studio can be seen below. I don't want any of these comments. Thanks for any help.
`
// ex6_page174.cpp : This file contains the 'main' function. Program
execution begins and ends there.
//
#include "pch.h"
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project >
Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open >
Project and select the .sln file
`
You can't.
For better or for worse, this is by design.

Include zxing in C++ project

I try to integrate zxing in an other C++ project. I'm using Visual Studio 2012 with Windows 7.
I would like to run the sample code from the zxing repository:
zxing example
If i compile my project i get an error:
zxing_integration.obj : lnk2001 unresolved external symbol
zxing_integration.exe fatal error lnk1120 1 unresolved external symbol
what I've done so far:
create an win32 console application named zxing_integration in the folder ...\workspace
create an folder ...\workspace\git and clone the zxing repository
create an folder ...\workspace\zxing-cpp\build and build the zxing project with the command line prompt cmake ..\workspace\git\zxing-cpp -G "Visual Studio 11 2012" (i think this step is not necessary)
Added under project settings->C/C++ -> additional include directorys (all configurations) the following pathes: ...\workspace\git\zxing-cpp\core\src and ...workspace\git\zxing-cpp\cli\src
After these steps nothing is red underlined or marked in Visual Studio, so i think the source files can be found. If i build the project i get the two errors. i think that the linker needs .lib files, but i can not found zxing libs in the project. Do i have to build the lib files?
It is strange that the error appears in line 258 source = ImageReaderSource::create(filename); and not in line 256 Ref<LuminanceSource> source;. It seems that LuminanceSource can be found.
Ref<LuminanceSource> source;
try {
source = ImageReaderSource::create(filename);
} catch (const zxing::IllegalArgumentException &e) {
cerr << e.what() << " (ignoring)" << endl;
continue;
}
For anyone stumbling over this dated question: there is a 'new' c++ implementation with lots of improvements compared to the upstream Java project: ZXingCpp
It can be built on Windows/macOS/Linux/Android/WASM.

FLTK version 1.3.2, Visual studio 2012 and the first example of Stroustrup's PPP book

PLEASE, just look at each step that I want to do and if any step is wrong just tell me to revise it.
1- Now I have the MS VS 2012 compiler on my C:\ drive, (C:\Program Files\Microsoft Visual Studio 11.0).
2- I went to fltk website and downloaded the version 1.3.2 because I thought it’s new so it can support better. (http://www.fltk.org/software.php?VERSION=1.3.2&FILE=fltk/1.3.2/fltk-1.3.2-source.tar.gz)
3- After unzipping that package on my desktop, I went to this path (C:\Users\CS\Desktop\fltk-1.3.2-source\fltk-1.3.2\ide\VisualC6) and found the “fltk.dsw” file there. I double clicked on it and pressed OK button. Every “.dsp” file was chosen in advance.
4- Then a message appeared saying, “Migrating solution projects and items”. And there were 84 items and after that some related operations occurred.
5- From the Build menu I chose Build Solution and clicked on it. It took some time to be finished and at the end, this message appeared:
*82> fltk_gldll.vcxproj -> C:\Users\CS\Desktop\fltk-1.3.2-source\fltk- 1.3.2\ide\VisualC6\.\Debug/fltk_gldll\fltk_gldll.dll
========== Build: 84 succeeded, 0 failed, 0 up-to-date, 0 skipped* ==========
6- Then I closed the Visual Studio and from the main folder of FLTK I opened the lib folder and copied seven lib files except README.lib file into this path of my machine (C:\Program Files\Microsoft Visual Studio 11.0\VC\lib).
7- Then I went to main folder of FLTK and copied the FL folder into this path (C:\Program Files\Microsoft Visual Studio 11.0\VC\include). Now that include directory contains a folder named FL.
8- And also I found fltk.sln file in this path (C:\Users\CS\Downloads\Compressed\fltk-1.3.2-source\fltk-1.3.2\ide\VisualC2010). I installed it too (then Build Solution). Shouldn’t would I install it also?
9- I then created a “Win32 Project” from Visual Studio named it to “Win32Project1”. And did the works as follows:
Win32Project1 --> OK --> Next --> Clicking on “empty project” --> Finish.
In “Solution Explorer” right click on “Win32Project1” --> choosing “Add” --> new item --> choosing “C++ file (.cpp)” --> naming the project to “Win32Project1” --> Add.
10- Now this new project is empty and in bottom there is only this message: VMware Virtual Debugger loaded successfully. That’s why because I installed VMware Workstation program on my machine I think.
11- Then I clicked on Project menu and chose Properties.
12- Then Linker --> Input and in the Additional Dependencies text field, I wrote this text: fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib
13- In the Ignore Specific default Libraries text field, I wrote libcd.lib.
14- Then C/C++ --> Code Generation, and in the Runtime Library the Multi-threaded Debug DLL (/MDd) is chosen in advance. So I simply clicked on OK only.
15- Then I wrote the simple code of page 1160 (D.5) as follows on that project and pressed F5.
#include <FL/Fl.h>
#include <FL/Fl_box.h>
#include <FL/Fl_Window.h>
//***************************
int main()
{
Fl_Window window(200, 200, "Window title");
Fl_Box box(0,0,200,200, "Hey, I mean, He llo, World! ");
window.show();
return Fl::run();
}
16- An error occurred saying:
E*rror 1 error LNK1104: cannot open file 'fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib' c:\Users\CS\documents\visual studio 2012\Projects\Win32Project1\Win32Project1\LINK*
So I returned to the Linker --> Input and in the Additional Dependencies text field, I clicked on <Edit…>, and separated each .lib file by a new line. And again ran.
Next error was this:
Error 1 error LNK1104: cannot open file 'fltkjpegd.lib' c:\Users\CS\documents\visual studio 2012\Projects\Win32Project1\Win32Project1\LINK
17- So I again went to the (fltk-1.3.2-source\fltk-1.3.2\lib) and copied all the .lib files except for readme, (there were 13 .lib files) and pasted them into that path (C:\Program Files\Microsoft Visual Studio 11.0\VC\lib) and reran the code. This time code succeeded. WOW.
18- So after this success I downloaded the Programming-code zip file from Stroustrup's website and copied all the .h and .cpp files (10 files) from the GUI folder into my include folder of this path (C:\Program Files\Microsoft Visual Studio 11.0\VC\include). There was also a Makefile file which I didn’t copy it into the include directory. And then I cleared the previous code and wrote the code written in page 441 (A first example) as follows into that project and ran it.
//
// This is example code from Chapter 12.3 "A first example" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilities
//------------------------------------------------------------------------------
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
Point tl(100,100); // to become top left corner of window
Simple_window win(tl,600,400,"Canvas"); // make a simple window
Polygon poly; // make a shape (a polygon)
poly.add(Point(300,200)); // add a point
poly.add(Point(350,100)); // add another point
poly.add(Point(400,200)); // add a third point
poly.set_color(Color::red); // adjust properties of poly
win.attach (poly); // connect poly to the window
win.wait_for_button(); // give control to the display engine
}
//------------------------------------------------------------------------------
19- There were 13 errors which first error was saying:
Error 8 error C2872: 'Polygon' : ambiguous symbol C:\users\cs\documents\visual studio 2012\projects\win32project1\win32project1\win32project1.cpp 20
20- So I used this snip code Graph_lib::Polygon poly; instead of this Polygon poly; and ran the code again. Again there were 11 errors, first is this:
*Error 9 error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Window::draw(void)" (?draw#Window#Graph_lib##MAEXXZ) C:\Users\CS\documents\visual studio 2012\Projects\Win32Project1\Win32Project1\Win32Project1.obj*
Now what any more effort I can to do?
I finally found and solved the problem. This is as follows:
First, there is no need to add some library named *Graph_lib* into the Linker Input text field even if we assume there is a library with that name in the whole of the machine!
The only needed change to be done to the project of code of page 411 (A first example) of PPP is to add the Graph_lib:: before the Polygon poly;. After that what we need is to adding some .cpp files to the project. I added all the .cpp files of GUI folder that I had downloaded them from Stroustrup's website to the project (they are Graph.cpp, GUI.cpp, Simple_window.cpp and window.cpp) and reran the project. It successfully showed the result.
In any way, I'm thankful of you nice guys, especially, "cup".

How to compile c++ file in visual studio?

I am new to Visual Studio and I don't know how to compile a .cpp file. I made just a single .cpp file (ctr + n => Visual C++ => C++ file) and I tried to compile it. But in place where normally there's a compile button (like with c#) there is strange 'Attach' button. I don't get what's going on, but I thought, Visual C++ might be some different version of normal C++. If so is that possible to compile normal C++ file in Visual Studio?
The problem is, Visual Studio don't really know, what to do with your .cpp file. Is it a program? Try the following:
File | New project
Visual C++ | Win32 | Win32 Project
Select a name and location for the project
Next
Choose Console application
Choose Empty project
Deselect Precompiled header
(optionally) Deselect SDL checks
Finish
Right-click on Source files and choose Add | New Item...
Choose C++ File
Choose name for this file
Write the following inside:
#include <stdio.h>
int main(int argc, char * argv[])
{
printf("Hello, world!\n");
return 0;
}
Press F5
You should, just as you did for C#, create a C++ project and add your source file to that. Then there will be all the build options you ever dreamed of.