Visual Studio Include Dll Child Project Header Issue - c++

I had a problem including a dll within visual studio the other day, and thought that I had solved all my problems, it turns out, however, that I did not. My problem is odd, too, because one option works, while the other does not. The behavior I am experiencing is a little strange, but I will try to explain it as best as I can. First, here is some code of my attempts(one of which works) to include a header from the dll I created:
#include <QtWidgets/QApplication>
#include <QMainWindow>
/*
This below works; it seems to be stepping backwards out of the
project and into the folder of the dll project.
*/
#include "../ArclightFramework/GameWindow.h" // This works.
/*
Below does not work, even though the path has been set in the
additional directories field of the project. Oddly, though, I
do get intellisense for the path the below.
*/
#include "ArclightEngine/ArclightFramework/GameWindow.h" // Does not work.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GameWindow f;
f.show();
return a.exec();
}
The first include works perfectly fine, and I can live with basing all my future includes off it. However, does anyone know why the second include does not work? And here is what I mean by "Does not work."
1>------ Build started: Project: ArclightEngine, Configuration: Debug Win32 ------
1> main.cpp
1>main.cpp(13): fatal error C1083: Cannot open include file: 'ArclightEngine/ArclightFramework/GameWindow.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
And here is even a picture of the same mouse over error:
You see, the strange thing is, I DID include the path to my "Additional import directories"; here is a picture:
And here is that directory, and the full path showing that everything SHOULD be found correctly.
My question is quite simple. Why can visual studio not find the include files?
Update: Here is another picture showing how Intellisense is offering completion of the include path, but again, it does not work afterwards!
Another update:
Alright, so I tried something new. This time instead of adding the absolute path to the Additional Include field, I added: "$(ProjectDir)../../" Once again, Intellisense offers completion for this path and the headers within it. But it does not recognize the files itself afterwards, but they do exist and the path is perfect. My path, using the macro above, would transform my include path to: "ArclightEngine/ArclightFramework/BLAH.h"
Here is a new picture showing the path I included:
I don't understand what the difference is between what I have done and the path that is working which is "#include "../ArclightFramework/GameWindow.h""
ALSO, apparently this include path also works now:
"#include "/Users/Krynn/Desktop/ArclightEngine/ArclightEngine/ArclightFramework/GameWindow.h""
TL;DR
All I want is to be able to type "#include "ArclightEngine/ArclightFramework/blah.h"

You've said a user include is:
C:\Users\Krynn\Desktop\ArclightEngine
And you're trying to include:
"ArclightEngine/ArclightFramework/GameWindow.h"
Thus the first path VS will try as you've used quotes rather than angle brackets is:
C:\Users\Krynn\Desktop\ArclightEngine\ArclightEngine\ArclightFramework\GameWindow.h
Which is simply both paths added together, so that's never going to work.
Hence including:
"../ArclightEngine/ArclightFramework/GameWindow.h"
Becomes:
C:\Users\Krynn\Desktop\ArclightEngine\..\ArclightEngine\ArclightFramework\GameWindow.h
Which becomes:
C:\Users\Krynn\Desktop\ArclightEngine\ArclightFramework\GameWindow.h
Hence this works. So another option should be to include:
ArclightFramework\GameWindow.h
Update:
Looks like your real problem was that you updated the configuration of "Release Win32" but you where building "Debug Win32" which has different settings. When updating setting that apply to all configurations and platforms (such as include paths) be sure to select "all configurations" and "all platforms" from the combo boxes.

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.

Link: fatal error LNK1561: entry point must be defined VS2015 developer cmd window

I have read a ton of this same question, but I appear to be doing everything correctly as all suggestions advise, but am still getting this error.
I have simple .cpp and .h files in C++ using Visual Studio 2015. My program runs perfect from the gui. I need to run it in the visual studio developer command window to get the results there, this is a verified console application. I have copied the files to their own directory using:
C:\RunDirectory>copy C:\SaveDirectory\
The system verifies that it copies all 15 files.
When I run this command:
C:\RunDirectory>cl Aprogram.cpp
Then I get the error.
I have a main that is returning an int, and this is a console application with the correct linker settings: Console (/SUBSYSTEM:CONSOLE)
Any ideas? I'm pretty stumped.
This is my driver file:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include "JollyBanker.h"
using namespace std;
int main()
{
JollyBanker theBanker;
theBanker.BuildQueue("BankTransIn.txt");
theBanker.ProcessQueue();
theBanker.DisplayResults();
return 0;
}
File Aprogram.cpp is a source code file, which is compiled and linked
into an executable by Visual Studio IDE. Assuming that default project
settings are used, this executable is located in "Debug" or "Release"
subdirectory of the directory that contains your solution and it is named
ProjectName.exe (where "ProjectName" is the name of the project
within the solution that contains Aprogram.cpp)
Also, you mentioned that you want to make sure it works outside VS. Note
that if you have used the default settings, you will have problems when you
run this executable on another machine. To solve this, I suggest that you
change the runtime library that you are linking to. To do this, right click on
the project in Solution Explorer and select "Properties". Go to "C/C++" -> "Code Generation"
and change the value of "Runtime Library" to "Multi-threaded Debug (/MTd)" for "Debug" configuration, or to "Multi-threaded (/MT)" for "Release" configuration.

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.

C++ Problems with #include <anyfile.h> when trying to compile a gstreamer app

I didn't find anything like this when I searched for it. I'm trying to make a simple gstreamer app based on code I found in another stack overflow thread. Whenever I try to compile it by going to the directory with command prompt and entering cl cppgstreamer.cc. Initially, the only include was #include <gstreamermm.h>, which gives me
cppgstreamer.cc(1) : fatal error C1083: Cannot open include file: 'gstreamermm.h
': No such file or directory
Even when I put cppgstreamer.cc into the same directory as gstreamermm.h. I then tried changing the include to
#include "C:\Users\MY_NAME\Documents\gstreamer c++\gstreamermm-0.10.10.2\gstreamer\gstreamermm.h"
with MY_NAME being replaced by my name.
This seems to work, but then it tries to do the includes in the gstreamermm.h, and they are in #include <file.h> form, so I get another fatal error C1083,except this time with init.h, or when I changed that, error.h. And they have dependencies. Is there a way that I can get my compiler to like the #include <file.h> syntax? I really don't want to go through the file and change every #include <file.h> to #include "file.h".
Sorry if this is a dumb question. I'm new to C++, although I've worked with C in the past.
I am using Microsoft Visual C++ Express 2010. Any help would be appreciated. Thanks!
You need to add the directory containing gstreamermm.h to include path. I don't have visual c++ here to check, but it's in somewhere in project properties under C/C++ .

getting the right compiler for C++

I am trying to learn c++ but most of the tutorials and books I have read or looked up teaches you this...
(I am assuming like most tutorials, they are teaching in the beginning to code either in win32 console or CLR console. In either case the following does not work.)
#include <iostream>
int main( )
{
std::cout << "Hello World\n";
return (0);
}
The IDE that i have is Visual C++ 2008 Express edition and they accept code like this
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Or like this
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
Honestly I do not no the difference in none of these and I am not sure if I should just download a older compiler so that it works. If someone can tell me what the difference in these are and where to go from there. That will help tremendously. Thanks
[Edited]
I am trying to do a simple hello world. But I get the error "system can not find path specified." I have screenshot that shows what the error looks like. It also is saying that my project is out of date when I clearly save the file before I build it. Apparently it can not find the executable file. I went to the debug fold and did not see any .exe file.
[Edited]
Ok, now When I try to build the project I get the following errors
1>------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>test.cpp
1>c:\users\numerical25\desktop\test\test\test.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\numerical25\desktop\test\test\test.cpp(6) : error C2653: 'std' : is not a class or namespace name
1>c:\users\numerical25\desktop\test\test\test.cpp(6) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Users\numerical25\Desktop\test\test\Debug\BuildLog.htm"
1>test - 2 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Here is the code I used
#include <iostream>
#include "stdafx.h"
int main( )
{
std::cout << "Hello World\n";
return (0);
}
Note: I tried using it with and without the #include "stdafx.h" When I tried it without the #include "stdafx.h", it said I might be missing it.
Not sure what you're asking. The first two examples you gave are valid C++ programs that should (will) compile with VC++. The third example is a C++/CLI program that must be compiled with the /CLR compiler switch (this is called Managed C++).
EDIT: Adding more specific information (from a comment below):
The first two examples are standard (native) C++ (albeit, the second example has MS-proprietary macros). They compile to native code. The third is C++/CLI (a "managed" extension to C++). It compiles to managed (.NET) code. Only the third snippet interacts with the .NET framework in any way. All three are absolutely buildable and runnable using the appropriate projects in VS 2008 (no command line necessary)!
Based on your latest update, it looks like you have probably modified some project properties and changed some paths. The app is building, but when you try to run it via VS (you should do this with <Ctrl>+F5, by the way), the executable cannot be found (there are several ways you could have messed this up by changing or playing with various settings).
Please note the difference between building and running. Building is the process of compiling and linking your source code. Running is launching the resulting executable. You seem to be confused between these (judging from your complaints about the "...out of date" dialog box). It is normal to get the "...out of date" dialog box if you try to run without rebuilding after you have made a change to the project (even if that change is saved). Just make sure you click "yes." You need to build the project before you can run it.
My recommendation is to completely delete your project and solution. Create a new empty project, as suggested elsewhere in this now-very-heavyweight thread, and don't modify any project settings. If this doesn't work, something is seriously wrong!
ANOTHER EDIT: Just for completion, since this question kept changing:
As others have already pointed out, your ultimate problem with the first snippet is the use of precompiled headers (PCH). PCH are turned on by default in new VS C++ projects. Their purpose is to speed compilation when many implementation files include the same set of headers -- preventing the compiler from having to parse the header files for each compilation unit.
You have three options:
(Recommended) Disable PCH -- Project Properties --> Configuration Properties --> C/C++ --> Precompiled Headers: Set Create/Use Precompiled Header to Not Using Precompiled Headers. (You don't need to do anything with the "stdafx.h" file or the #include for it.)
Place your commonly used #includes in "stdafx.h". In your case, you would put #include <iostream> in "stdafx.h".
Place your #includes after `#include "stdafx.h". Microsoft requires that the "stdafx.h" be the first included file in a compilation unit.
A minor point, which I don't see elsewhere in the answers: When using precompiled headers, such as your stdafx.h, you need to include them first. Change it to:
#include "stdafx.h"
#include <iostream>
and that should fix the errors about it.
Alternatively, it may be easier to simply switch off precompiled headers: Project > Properties > Configuration Properties > C/C++ > Precompiled Headers > Switch first option to "Not using precompiled headers". They can be useful for big projects but will just be awkward and annoying while you're learning, since they have extra rules (like this "must be included first") which aren't requirements of standard C++ .
The "difference" is pedantic. The latter are just Microsoft-specific entry points.
As you are learning C++, I recommend you use a compiler, and preferably an operating system that lets you focus on C++, and not the platform. For this I recommend g++, on an Linux distribution such as Ubuntu.
Try this tutorial, there are many others that are similar that quickly let you overcome being tied to the tools, and focus on C++.
int main();
int main(int argc, char* argv[]);
These are standard C++.
int _tmain(int argc, _TCHAR* argv[]);
int wmain(int argc, wchar_t* argv[]);
These are Windows-specific to handle Unicode arguments. See What is the difference between _tmain() and main() in C++?.
int main(array<System::String^>^ args);
This is not C++. This is C++/CLI.
For best portability, always use the first form.
Also,
int main(int argc, char** argv, char** envp);
This is a usually seen POSIX extension. Windows supports this form of main too. The envp means (pointer to) environment variables.
int main(int argc, char** argv, char** envp, char** apple);
This is for Mac only, obviously.
void main();
And this is wrong (nonstandard, some compilers (e.g. gcc) will reject it).
Visual C++ Express will compile the first example just fine.
However, you need to ensure the proper project settings:
Create an "Empty Project"
"Add a new item..." to the project via the "Project" menu. Select C++ (.cpp) file.
Copy/Paste code into new file
Press F5 to compile and run.
When "Project is out of date" dialog appears, press "Yes" (build the project)
The steps above ensure VC++ Express does not treat your file as a special Win32/Windows console application.
EDIT: added additional step 5 to prevent "Can't find..." dialog.
I managed to get the same dialog by making sure the exe file does not exist, and answering "No" to the build dialog. With a clean, empty project the exe file does not exist yet. It must be built first. If you answer "no" don't build it, VC++ dutifully does not build the exe and later complains about not being able to find it when it tries to run it later.
As STingRaySC pointed out, all three of your examples will compile in VC2008 express; it's just that examples 2 and 3 are what VC2008 Express will load up initially when you create a project (one of the examples is for Managed C++, as STingRaySC mentioned).
You can just delete the code in your second example (the C++ Win32 Console Application project) and paste in the more standard hello world program from your first example. It should compile and run just fine in VC2008 Express - it did for me.
I. Precompiled header
#include "stdafx.h"
is some kind of tricky stuff that comes your way.
If you create a project VC will normally switch on precompiled header.
This means that one header stdafx.h is created which is compiled only once.
This is done to speed up compile time in big environments. If you start C++
it will confuse you.
If you use stdafx.h it has to be the first header in the cpp file.
II. Unicode (Utf16)
int _tmain(int argc, _TCHAR* argv[])
Microsoft uses UTF16 to implement unicode strings.
This means you get two versions of main.
int main(int argc, char* argv[])
int main(int argc, wchar_t* argv[])
This is also confusing if you start.
To simply start you can use whatever editor you want.
Create the file.
Open a Visdual studio 2008 command prompt
cl main.cpp
main.exe
and you will see Hello World using code from books.
Afterwards try to understand some of the settings of VC.
But you should always use an empty project.
Else you have to care about stdafx, UNICODE, ...
_tmain with the _TCHAR argv is the way the C runtime allows you to handle unicode. If _UNICODE is defined, then _tmain will expand to wmain, and the _TCHAR argument will be of type wchar_t. If _UNICODE is not defined, then _tmain will expand to main, which will be the ANSI standard.
Therefore, so long as _UNICODE is not defined, the second snippet you posted is compliant with the standard.
Lots of waxing lyrical and some misinformation for you sift through already, but I suggest following wonsungi's advice. But to clarify his advice:
File->New->Project
Select Project Type "Win32", then Template "Win32 Console Project"
Give the project a name and location
OK
Select "Application Settings"
Check "Empty Project"
In the "Solution Explorer", right click the "Sources" folder, then Add->New Item
Type the name of the file, in the "name" box using a .cpp extension (you can ignore the templates if you wish).
Enter your code in the new file.
Woot!! I figured it out!!! Below is my original code
#include <iostream>
int main( )
{
std::cout << "Hello World\n";
return (0);
}
It was missing the header file #include "stdafx.h" . So I had to include it in there so I added it like this
#include <iostream>
#include "stdafx.h"
int main( )
{
std::cout << "Hello World\n";
return (0);
}
I was still getting an error like what you see in my edited question at the bottom. So What I did is I took #include and added it in my header file and then it worked!!!!!
Even the the books and alot of tutorials show to add #include to the actual cpp, for some reason in express edition I had to add it to header for it to work. I don't know WHY but it's a solution and now it works.
Download and install Dev-C++ on your system. If the code doesn't work on Visual C++, try it out on Dev-C++ (which uses the GCC compiler). You may get the same results or a different error message. Whenever you get an error message you don't understand, do a Internet search for the error message.