Visual Studio throwing LNK2019 and solution missing headers/source files - c++

-- Updates --
Adding the source file settings.cpp directly to the project via Add -> Existing Item resolved the LNK2019 (as I suspected it couldnt find it).
-- Updated Question--
How to specify a source file directory without having to add all the files within it manually as described in the update above? This is clearly achievable for the header files (as described below by adding the directory to the settings, is this not the same for source files?
-- Original Question --
I'm working on replicating a project from CPython into C++ as a challenge to learn more C++ but I can't seem to get the environment established so that I can compile a test run. When I build the solution, it throws a LNK2019 which I know has something to do with the Linker unable to locate the symbols. I have read through numerous solutions on SO that say to updated the properties with the directories of the files, but they do not resolve the issue.
The issues currently stand at:
Some of the headers from other directories show in the explorer, but some do not, why?
The source files are not found and therefore LNK2019 is thrown, cannot resolve, how to?
Here is the layout of my project:
/root
/proj-cmd
/src/main/cpp
/proj/cmd
-> main.cpp
/proj-core
/src/main/cpp/
/proj/cmd
-> command.h
-> base_command.h
-> base_command.cpp
/proj/utils
-> settings.h
-> settings.cpp
The content of main.cpp for testing of environment:
// astro
#include <astro/core/util/settings.h>
// stdlib
#include <exception>
#include <string>
#include <iostream>
using namespace std;
// astro entry point
int
main(int argc, char *argv[])
{
if (conf().hasKey("APP_CWD"))
{
cout << "APP_CWD is: " << conf().getKey("APP_CWD") << endl;
}
else
{
cout << "APP_CWD was not found" << endl;
}
}
In order for #include <astro/core/util/settings.h> to work, I updated the include directories in the properties:
However, in the explorer only command.h and settings.h are shown, not base_command.h:
Additionally, the base_command.cpp and settings.cpp do not display in the source files either, so I updated (similar to the include directories) the source directories:
That takes care of the first issue I am noticing, but now onto LNK2019. I believe this is a related result of the former problem, in that the source files are unknown:
So following many other SO posts, I tried to update the Linker settings without success:
I'm not very familiar with the Visual Studio 2017 environment, so if somebody could provide input as to how to configure these settings so that I can compile I'd appreciate this.

You need to add all .cpp files to your project as Existing Items. Just being in a directory is not sufficient for the IDE to know to compile those files. Headers are found by directory via #include, but you should still add them to your project as Existing Items to make it easier to navigate them in the tree view.
This is why you are getting linker errors: the code in settings.cpp and base_command.cpp are never getting built.
See Microsoft Docs

Related

Unable to include Magick++.h for image processing: "no such file or directory"

I'm setting up a c++ visual studio project to use ImageMagick's api, Magick++, for image processing. However, when I try to include <Magick++.h> in the only cpp file in the whole solution/project, I encounter this error:
fatal error C1083: Cannot open include file: 'Magick++.h': No such file or directory
I tried right-clicking Magick++.h in my code and pressing open document <Magick++.h>. This lead to an error message, which says the file is not found in current source file's directory or in build system paths. However, in the error message, the Build System Path clearly says the path to the include directory.
I have:
added the include directory of ImageMagick-7.0.9-Q16 in the project's properties->C/C++
->Additional Include Directories.
added the lib directory of ImageMagick-7.0.9-Q16 in the project's properties->Linker->Additional Library Directories
added CORE_RL_Magick++_.lib, CORE_RL_MagickCore_.lib, and CORE_RL_MagickWand_.lib in the project's properties->Linker->Additional Dependencies
Made sure everything is x64
Set the configuration to release
I somehow made Magick+++_demo project, the one that comes with magick++, work after tinkering with the settings. However, I cannot make other projects/solutions work. I have checked the settings of the demo project and tried to replicate it in my project where appropriate, but I cannot make my own project work.
this is the only code:
#include "pch.h"
#include <Magick++.h>
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
I have been googling and trying to make this work for the last 6 hours. Any help is hugely appreciated.

Autotools project and external libraries on Eclipse

I'm trying to build an Autotools project using Yocto ADT Plugin and Eclipse Luna.
I need to include some external libraries to the project and to be more specific the boost libraries.
Let's consider the easiest case scenario: header only library.
I should be able to #include into my project.
I'm trying to compile a test code:
#include <iostream>
#include <boost/lambda/lambda.hpp>
using namespace std;
int main(void) {
cout << "Hello World" << endl; /* prints Hello World */
return 0;
}
but I'm getting the error: "fatal error: boost/lambda/lambda.hpp: No such file or directory"
Of course I have to tell the compiler where to find the library.
I tried to do it in different ways but nothing succeded.
To make some examples:
Project -> Properties -> C/C++ General -> Path and Symbols
There I specified the path for downloaded libraries and for compiled libraries (not needed in this case but added for generality):
The include is correctly reported under project explorer but the error persisted.
Then I tried to work on Project -> Properties -> C/C++ General -> Preprocessor Include:
Still getting the same error.
I tried then to include configuring the Autotools adding the -I option:
Of course it didn't succeed either.
After every failed build attempt I run a "Clear Project" and "Reconfigure Project" just to be sure to start all over.
The strange thing is that if I select the boost/lambda/lambda.hpp in the editor and I do "Open Declaration" it finds the file:
At this point I don't know what to do, clearly I'm missing something.
Could you possibly help me ?
Additional Note: If I start an C++ Executable Project using GCC the library is recognized and I have no problems.
So I think the issue is within the Autotools or Yocto ADT.
I even added the boost libraries to my Yocto build and SDK but it's not working.
I managed to succesfully compile adding to the /src/Makefile.am the include to the libraries.
Still I don't understand why this is different from changing the Autotools configure flag.
If someone has an answer, please care to explain.

#include <opencv2/opencv.hpp> not working in VS 2013

I have VS2013 community edition, I just installed OpenCV in a directory c:\openCV3 and there is a build subfolder with an include subfolder of that etc, everything looks normal. So I create an empty project with the line#include <opencv2/opencv.hpp> but I get
Error 1 error C1083: Cannot open include file: 'opencv2/opencv.hpp': No such file or directory d:\devt\cplusplus\opencv\test1\test1\source.cpp 1 1 Test1
However I have modified my project's additional include directories to this:
C:\OpenCV3\build\include\opencv;C:\OpenCV3\build\include\opencv2;C:\OpenCV3\build\include;%(AdditionalIncludeDirectories)
But nothing doing, the mistake does not go away. Pretty much the same question has been asked before but the answers do not work for me.
Update:
I right clicked on <opencv2/opencv.hpp> and, in the popup menu chose OpenDocument.
I got the following message box:
What I found surprising is that there is no mention of my set of additional include directories.
Instead of use the includes C:\OpenCV3\build\include\opencv and C:\OpenCV3\build\include\opencv2, try to use C:\OpenCV3\build\include\. When you call an include you're already telling the folder you are using:
#include <opencv2/opencv.hpp>
In that case, VS is searching opencv2/opencv.hpp in folder opencv2... VS must search in the folder include, so it will found opencv2/opencv.hpp...
(or you can try to modify your include to "#include "
Hope it helps.
I faced similar issues with VS2013 - it felt that Additional Include Directories was not working.
However, as I figured out later, when editing
Project -> Properties -> C/C++ -> General -> Additional Include Directories
I didn't pay attention on the selected Configuration: on the top right corner of the properties panel (Debug/Release etc.).
You can choose All Configurations so that your changes apply to both Release and Debug building modes, or you should setup proper individual configurations (set Additional Include Directories etc.) per build type.

Linking CodeBlocks to Poppler Library

I'm relatively new to programming in C++ and while I have some experience in general coding practices, conventions etc... Recently I have come to precipice of my (limited) knowledge.
Basically I wish to write a program that will allow me to extract the annotations from a PDF file. With some research I discovered that the Poppler library would allow me to do this. So I downloaded it and began the arduous process of building it for CodeBlocks (MinGW) on Windows Vista.
For those interested, the following site provided invaluable information with regards to the building of Poppler with Cmake:
http://www.seppemagiels.com/blog/building-poppler-windows-using-mingw>
Anyway, onto my current dilemma. Having followed the out of source conventions of Cmake I have a file structure like so:
...\Work\
..............poppler-0.22.2
..............poppler-0.22.2_Build
In the "poppler-0.22.2_Build" folder there is a " libpoppler.dll.a " file which i have been led to believe is a Library folder. I have then followed the instructions as described here:
http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/
I then linked to the libpoppler.dll.a file in the "poppler-0.22.2_Build" directory and the .h files which were in the original source directory (i.e. poppler-0.22.2).
Now my question is what do i need to write in my main.cpp such that i can use the Poppler functionality. At first i just wrote:
#include "poppler.h"
However, this returned with a "No such file or directory" error.
Then i tried:
#include "poppler-qt4.h"
This then executed however I was informed later in my code that "poppler" has not been declared.
Then I tried:
#include "poppler-qt4.h"
#include "C:\Users\...\poppler-0.22.2\cpp\poppler-document.h"
Which then returned a "undefined reference to 'imp_ZN7poppler8document14load_from_fileERKsS2_S2_'" error...
So that's where I am right now, I have absolutely no idea how I should continue and I was hoping someone could walk me through the steps I need to take to get Poppler to work i.e. as in how do I get the library to link, if that is indeed the problem, or how do I overcome the "imp_" error. I really am at my wits end with this problem...
Thanks in advance for any help you can supply.
P.S. My main.cpp so far:
#include <iostream>
//#include "poppler.h"
#include "poppler-qt4.h"
#include "C:\Users\...\poppler-0.22.2\cpp\poppler-document.h"
using namespace std;
int main()
{
const string dir = "C:\\Users\\...\\TestPDF.pdf";
poppler::document *doc = poppler::document::load_from_file(dir)
return 0;
}
In Code::Blocks, right-click the name of your project and select "Build Options...". Select the option in the left-most menu that says the name of your project (should be the first option) and click "Linker Settings". Now press the "Add" button and browse to your DLL file, then press "Ok".
To allow including the header files of your library (without writing down the full path in your source code), you should tell add their location to the compiler's include path. You can do this on the "Search Directories" tab in the same window. Make sure the "Compiler" sub-tab is selected and press "Add". Browse to the the directory containing the header files and press "Ok".
Hope this helps.

unable to link FMOD library to VS2010 project

I am trying to link FMOD to my project, which I did very easily in the past in Visual Studio 2008.... So I have placed the fmodex_vc.lib and the fmodex.dll file in my project directory, added them to my project's solution explorer, then created a SoundMgr.h file which includes the fmod.h file
#include "include\fmod\fmod.h"
Where fmod has been placed in the include\fmod folder and opens ok if i right click on the above code and click "Open Document"...
But if I try to write any code at all, including a simple "using namespace FMOD" it tells me that it FMOD is undeclared or unidentified.... am I missing any step?
EDIT:
What the class looks like so far is:
#pragma once
#include "main.h"
#include "include\fmod\fmod.hpp"
#include "include\fmod\fmod_errors.h"
#include "include\fmod\fmod.h"
class SoundMgr{
void init();
};
void SoundMgr::init(){
FSOUND_Init (44100, 32, 0);
}
And the error is:
Error 1 error C3861: 'FSOUND_Init': identifier not found
And that's for any line of the sample code that I try import from this quick guide:
GameDev FMOD quick guide
I tried adding the library as an additional dependency in the Input section of the Properties/Linker and I get
1. fatal error LNK1181: cannot open input file 'fmodex_vc.lib'
Any of these errors ring a bell?
Don't you want fmod.hpp to get the c++ features?
you can include the headers path in C/C++ > General and library path to Linker properties and include the dll's in you project. In this case you have the files in you release/debug dir
Right so I eventually fixed it by removing the Additional Dependency in the Input section of the Linker and instead adding Include and Library directories in in Configuration Properties\VC++ directories.... Most articles I found advise to use the actual full path to the FMOD installation folder, but since I want this project to be portable and self contained, i created a "lib" and "include" folder in my project and put those files in them... (used the directories "\lib" and "\include" in the project properties which I am assuming links to the project folder, have never done this before but am hoping it won't cause dependency issues if I compile this on a different machine)...