C++ LInker error (Visual Studio C++ 2010) - c++

I tried to create empty project for Visual Studio.
// OpenGL1.cpp : main project file.
// #include "stdafx.h"
#include "windows.h"
#include <GL/gl.h>
#include <iostream>
using namespace System;
int main()
{
std::cout << "Hello World" << "\n";
return 0;
}
Having configured these dependencies:
opengl32.lib;glu32.lib;olepro32.lib;%(AdditionalDependencies);C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl;
And I got this error:
.NETFramework,Version=v4.0.AssemblyAttributes.cpp
LINK : fatal error LNK1104: cannot open file 'C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl.obj'
Can you explain why this happens and how to remove the error?

The "dependencies" refer to the filenames of libraries which the linker should use, not to include paths. Include paths are for the compiler, not for the linker.
You must first tell the linker where to find the OpenGL library file:
http://msdn.microsoft.com/en-us/library/1xhzskbe%28v=vs.100%29.aspx
And then, as a dependency, you specify only its name, not a full path. In this case, opengl32.lib.

Related

How to use a C++ library method in a visual studio project

I'm trying to test a method from a static library that I created. The method from the library just prints something to the console. I have added the directory in the properties tab and added the linker input. However, the project still does not recognise the library. Would anyone be able to help. Any help is appreciated.
Libary header:
void TestLiabry();
Libary method:
void TestLiabrys()
{
cout << "Hello" << endl;
}
Project I want to use the method in:
#include <iostream>
#include "TestLibary.h"
int main()
{
std::cout << "Hello World!\n";
TestLiabry.TestLiabry();
}
I added the library in the linker like this:
Linker -> Input -> Additional Dependencies -> C:\Users\jorda\Downloads\TestLiabry
It pops out this error:
Severity Code Description Project File Line Suppression State
Error MSB6006 "link.exe" exited with code 1104. Project1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets 1010
And this lnk error:
Severity Code Description Project File Line Suppression State
Error LNK1104 cannot open file 'C:\Users\jorda\Downloads\TestLiabry.obj' Project1 C:\Users\jorda\Downloads\Project1\LINK 1
There seemed to be an error in my linking of the path to the library where I didn't include the library .lib. Only include the path and not the path and lib file in the directory.

How to compile program that uses boost::filesystem?

I'm trying to compile a sample program that uses boost::filesystem:
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path full_path(boost::filesystem::current_path());
std::cout << "Current path is : " << full_path << std::endl;
}
I've downloaded and compiled boost 1_72, added my_path_to_boost to include directories and my_path_to_boost\stage\lib to include lib directories
When I try to compile the program, I'm getting following error:
Severity Code Description Project File Line Suppression State Suppression State
Error LNK1104 cannot open file 'libboost_filesystem-vc142-mt-gd-x64-1_72.lib' current-path D:\My Projects\filesystem\current-path\LINK 1
I have verified that libboost_filesystem-vc141-mt-gd-x64-1_72.lib is located in my_path_to_boost\stage\lib.
I'm using Visual Studio 2019
What am I missing? Is there any way I can see where VS is looking for the file?

C++ Boost Link error

I am working on Windows 10 and I downloaded Boost 1.60 for Visual Studio 2015.
My first code snippet looks as:
#include <boost/thread.hpp>
#include <vector>
#include <iostream>
#include <sstream>
#include <cmath>
#include <iostream>
using namespace std;
void main()
{
std::cout << "Hello World";
}
I get the error:
>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc140-mt-gd-1_60.lib'
I have provided path for boost and also libraries as shown in pics:
You need to compile the library before using it. Here's how to compile it:
In your Windows Start menu open the "Developer Command Prompt for VS2015". Then inside the opened command prompt, execute those commands:
cd C:\boost_1_60_0
bootstrap.bat
.\b2 runtime-link=shared toolset=msvc-14.0
Wait for a couple of minutes, since compilation takes a while.
Specify in your project in Linker -> General, the Additional Library Directories path as C:\boost_1_60_0\stage\lib, and in C++ -> General the Additional Include Directories path as C:\boost_1_60_0
You should now be able to compile your code without problem.

Visual Studio Compiler Error

I was making a simple DLL as a test in visual studio 2010.
Here is the code for SimpleCPP.cpp
#include iostream
#include "SimpleH.h"
namespace nmspace
{
void myclass::Crap()
{
std::cout << "Test." << std::endl;
}
}
Here is the code for the header file
#include <iostream>
namespace nmspace
{
class myclass
{
public:
static __declspec(dllexport) void Crap();
};
}
My problem is when I compile I get an error that says that visual studio can't find the file SimpleDLLd.dll. In closer inspection I see that when the program is compiling visual studio adds a d to the release files. For example when the DLL is supposed to be SimpleDLL.dll (The project name is SimpleDLL) visual studio adds a d and outputs SimpleDlld.dll. I tried doing the same thing in another project and it did the same thing. I then proceeded to Visual Studio 2013 and copy and pasted the contents of the cpp and header files into new files and surprisingly got the same exact result as Visual Studio 2010. How would I fix this error? Thank you for responding.
Check the name of the build target in your project file settings. The name of the resulting file should be in the
Linker->General->Output File
setting in the project which is usually $(OutDir)$(TargetName)$(TargetExt) by default.

Visual C++ can't open include file 'iostream'

I am new to C++. I just started! I tried a code on Visual C++ 2010 Express version, but I got the following code error message.
------ Build started: Project: abc, Configuration: Debug Win32 ------
ugo.cpp
c:\users\castle\documents\visual studio 2010\projects\abc\abc\ugo.cpp(3): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is the code:
// first.cpp -- displays a message
#include <iostream> // A PREPROCESSOR directive
int main(void) // Function header
{ // Start of a function body
using namespace std;
cout << "Come up and C++ me sometime.\n"; // Message
// Start a new line
cout << "Here is the total: 1000.00\n";
cout << "Here we go!\n";
return 0;
}
Replace
#include <iostream.h>
with
using namespace std;
#include <iostream>
Some things that you should check:
Check the include folder in your version of Visual Studio (in "C:\Program Files\Microsoft Visual Studio xx.x\VC\include", check for the file which you are including, iostream, make sure it's there).
Check your projects Include Directories in <Project Name> → Properties → Configuration Properties → VC++ Directories → Include Directories (it should look like this: $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;)
Make sure that you selected the correct project for this code
(menu File → New → Project → Visual C++ → Win32 Console Application)
Make sure that you don't have <iostream.h> anywhere in your code files, Visual Studio doesn't support that (in the same project, check your other code files, .cpp and .h files for <iostream.h> and remove it).
Make sure that you don't have more than one main() function in your project code files (*in the same project, check your other code files, .cpp and .h files for the* main()` function and remove it or replace it with another name).
Some things you could try building with:
Exclude using namespace std; from your main() function and put it after the include directive.
Use std::cout without using namespace std;.
I had this exact same problem in Visual Studio 2015. It looks like as of Visual Studio 2010 and later you need to include #include "stdafx.h" in all your projects.
#include "stdafx.h"
#include <iostream>
using namespace std;
The above worked for me. The below did not:
#include <iostream>
using namespace std;
This also failed:
#include <iostream>
using namespace std;
#include "stdafx.h"
You are more than likely missing $(IncludePath) within Properties → VC++ Directories → Include Directories.
Adding this should make iostream and others visible again. You probably deleted it by mistake while setting up your program.
If your include directories are referenced correctly in the VC++ project property sheet → Configuration Properties → VC++ directories → Include directories, the path is referenced in the macro $(VC_IncludePath).
In my Visual Studio 2015 this evaluates to:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
using namespace std;
#include <iostream>
That did it for me.
It is possible that your compiler and the resources installed around it were somehow incomplete. I recommend re-installing your compiler: it should work after that.
I got this error when I created an 'Empty' console application in Visual Studio 2015. I recreated the application, leaving the 'Empty' box unchecked. It added all of the necessary libraries.
Make sure you have Desktop Development with C++ installed.
I was experiencing the same problem, because I only had Universal Windows Platform Development installed.
Microsoft Visual Studio is funny. When you're using the installer, you must checkbox a lot of options to bypass the .NET framework (somewhat) to make more C++ instead of C# applications, such as the CLR options under desktop development... in the Visual Studio installer.... the difference is the C++ Win32 console project or a C++ CLR console project.
So what’s the difference? Well, I'm not going to list all of the files CLR includes, but since most good C++ kernels are in Linux... So CLR allows you to bypass a lot of the Windows .NET framework because Visual Studio was really meant for you to make applications in C#.
Here’s a C++ Win32 console project!
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!" << endl;
return 0;
}
Now here’s a C++ CLR console project!
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine("Hello, World!");
return 0;
}
Both programs do the same thing .... the CLR just looks more frameworked class overloading methodology, so Microsoft can great its own vast library you should familiarize yourself with if so inclined.
Keywords (C++)
Other things you'll learn from debugging to add for error avoidance:
#ifdef _MRC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
If you created an environment variable with the name IncludePath, try renaming it to something else.
This name will override $(IncludePath) inside project properties.
Quick fix for small programs:
Add: #include <cstdlib>
In my case, my Visual Studio 2015 installed without selecting C++ package, and Visual Studio 2017 is installed with the C++ package. If I use Visual Studio 2015, opening a C++ project will show this error, and using Visual Studio 2017 will be no error.
I had this problem too. I used this code (before main();) in Visual Studio 2022, and it turned OK:
#include "pch.h"
#include <iostream>
using namespace std;
using namespace winrt;
using namespace Windows::Foundation;
In my case, the error occurred when I created a file in VS Code, without giving the .cpp extension. It resolved when I renamed it with the .cpp.
// first.cpp -- displays a message
#include <iostream> // a PREPROCESSOR directive
using namesapce std;
int main() // function header
{ // start of a function body
///using namespace std;
cout << "Come up and C++ me sometime.\n"; // message
// start a new line
cout << "Here is the total: 1000.00\n";
cout << "Here we go!\n";
return 0;
}