Iam trying to write a console application in 64 bit.I have linked the required library in the
Properties->Linker->Addidional Input->fltLib.lib
It wouldnt work so I added Addidional Directory in
Propertied->Linker->General->Addidtional Directory->C:\Program Files (x86)\Windows Kits\10\Lib\10.0.14393.0\um\x64
It still gives unresolved symbol FilterConnectCommunicationPort
I also tried copying the fltlib.lib file in my local directory and then
#pragma comment(lib, "fltLib.lib")
Still it complains about unresolved external externals.
After that I tried adding header directory in
C/C++->General->Additional Include Directory->C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um
Still it gives errors saying unresolved external symbols.
I have also tried including the headers in an extern "C" block.
I'm really confused as to what I'm doing wrong.
In Visual Studio you have to add the folder, which you have already done by setting the property Linker > General > Additional Library Directories. You also need to set the name of the file you will be linking against. This is done by putting the "fltlib.lib" in the Linker > Input > Additional Dependencies field.
If you have multiple lib files in one directory it might be easier to use the Linker > Command Line option: [PATH TO LIB FOLDER]*.lib". Keep in mind that statically linking (against lib files) increases the size of your build files, so unnecessary linking against everything should be avoided
Related
I have a C++ .h and .cpp file from another project that I want to include into my project.
I don't want to copy the files over into my project since I want any changes to those files be applied to both projects.
I've included the directory of the file's folder in the
Properties->VC++ Directories->Include Directories
I've also included the folder in the
Properties->C/C++ -> General -> Additional Include Directories
The .h files seem to work. If I rename the include to anything other than
#include "myfile.h"
The cpp file gets unknown definitions.
When I compile. The error is
fatal error C1083: Cannot open source file: '..\..\..\..\..\..\my project\myfile.cpp': No such file or directory
If I remove the cpp file from the project. Then I get a long list of unresolved functions.
error LNK2019: unresolved external symbol "public: unsigned long __thiscall myclass::myfunction"
How can I include both the .h and .cpp file into my second project?
For cpp files you can just use right mouse click on project, select "add"->existing item.
Then they should compile with others, when a build initiated.
Slightly more complicated with headers. There is two ways to use #include directive:
with < > and " " braces
When " " braces used, compiler treats path as relative (if not absolute used) to location of cpp file.
When < > braces used, compiler looks for file in something like system include folders. For example - stdlib headers folder and windows.h location folder. Properties entry Additional Include Directories also goes there.
I suggest you to change projects structure and extract shared features from both projects to compile it as static library. Place shared headers in some subfolder inside library project and refer then as
#include "mylibHeaderDir/someheader.h"
In dependent projects, after setting Additional Include Directories you can refer theese includes as
#include <myLibHeaderDir/someheader.h>
This approach will help you in future, as you can reuse that shared module in every project you want.
About how to create and link static library you can read this article http://msdn.microsoft.com/en-us/library/vstudio/ms235627(v=vs.110).aspx Version of visual studio may be differ, but basics are the same.
You can't just pick files like that. There are two reasonable ways to solve it. 1, shared the file by means of a Code Versioning System (e.g. svn/git). 2, compile the the .cpp into a library and link to that library.
If the cpp can be used by multiple projects, it must mean that the code is something common. That means you should compile that code by itself into a library and then share that library. Compiling the same cpp into multiple libraries is likely to result in conflicts later if two such libraries are ever needed to work together.
Try to drag them into your solution?
You can create a new folder in your solution, and drag them all into this folder!
So currently I'm trying to use the VISA library from National Intruments and the IVI Foundation to read/write commands to various external devices.
I am relatively novice with my IDE: Microsoft Visual C++ Express 2010 and this is my first time trying to use a third party library that requires more than a .h import.
Basically I have a directory with 3 header files, a directory with 3 .lib libraries and a directory with 7 DLLs. They have no documentation as to what any of the individual files do, only the library as a whole. So, I need to be able to get all of these files associated with my project.
Currently I have all the headers imported in my header file and the header directory added to the include directories in the project properties. I also have the directory containing the .lib files added to the library directories in the project properties. I assumed that .lib files would link to the DLLs, but apparently that is not the case because I'm getting the error:
VISA Console 2.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _wmain
This error occurs when using any function from the library. Here is my code currently:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
ViStatus status;
ViSession defaultRM, instr;
status = viOpenDefaultRM(&defaultRM);
return 0;
}
The project will build when I comment out the viOpenDefaultRM command, so I assume that means I can use the objects from the library and not the commands. Since I have the 3 object declarations that build just fine.
Okay this is all my information, hopefully someone can help and hope this helps someone else!
In addition to having the directory for the .lib file(s) added to the library directories property, you need to also add the actual libraries that the linker should search.
Add the libraries to the project's
Configuration Properties | Linker | Input | Additional Dependencies
field.
The DLLs are not necessary for the build process, but to run the program they should be in a directory inthe PATH or in the same directory as the program file.
Have you added to the project properties the additional dependecies?
Under "Linker->Input" find "Additional Dependecies" and place there the libs that you got from
I have a solution with two projects on VS2010.
The main project references and depends on the second one, which is built as a static library. The second one uses a static third-party library that is not build within the solution, but is only referenced in the second project's linker settings.
If I try to generate the solution, VS fails and indicates that he didn't find the third-party library. I do not understand why, since the second project's compiled static lib is big enough and seems to "contain" the 3rd-party library.
So far, I see only two solutions to my problem, which I would rather avoid:
Add the 3rd-party library to the main project's linker settings
Include the whole 3rd-party library in my solution and compile it with
Is there any other way to resolve this problem?
EDIT : The problem occurs when compiling the main project, the compiler outputs : LINK : fatal error LNK1104: cannot open file 'wxbase29u.lib' (I'm using wxWidget in my second project)
EDIT2 : I put the -verbose option for linking on, and it seems like the references to the 3rd-party library actually still exists in Project2.lib :
Searching ..\MyAppConfig\Bin\Win32\Release\MyAppConfig.libĀ :
"public: static void __cdecl ConfigWindow::Open(void)" (?Open#ConfigWindow##SAXXZ) found
Referenced in main.obj
Loaded MyAppConfig.lib(configWindow.obj)
/DEFAULTLIB:wxbase29u processed
/DEFAULTLIB:wxbase29u_net processed
/DEFAULTLIB:wxbase29u_xml processed
/DEFAULTLIB:wxregexu processed
/DEFAULTLIB:wxexpat processed
/DEFAULTLIB:wxjpeg processed
/DEFAULTLIB:wxpng processed
/DEFAULTLIB:wxtiff processed
/DEFAULTLIB:wxzlib processed
...
...
LINK : fatal error LNK1104: cannot open file 'wxbase29u.lib'
Funny thing is that I don't even use the other wxWidgets libraries in Project2, but visual studio seems to be searching for all of them though :/
Here's how you should setup your project:
Project 1 (main)
Additional dependencies: Project2.lib
Project 2
Additional dependencies: ThirdParty.lib
Build order: Project 2 -> Project 1
If your project is setup like that and it does not link, then it just means the path to your libraries isn't correctly set (under "Additional include directories"). So just make sure that your project additional dependencies are correctly set and that the include directories point to the place where the libraries you need are located.
I'm trying to compile a c++ source code file from the DXC competition.
The instructions are:
To compile any of the C++ examples (or a DA written in C++) under Windows, MS
Visual C++ 8.0 (2005) is required. Make sure to add %DXC_HOME%\Lib and
%DXC_HOME%\Include to your library and header search paths respectively, and add
dxcApi.lib to your list of libraries (or dxcApid.lib if compiling in debug
mode).
I added Lib and the Include libraries to the library and search paths and it imported them. What I didn't understand is the meaning of the second step: "add dxcApi.lib to your list of libraries" - what does it mean?
Without this step I'm getting linker errors, such as:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: _thiscall
Dxc::CandidateSet::~CandidateSet(void)"
(_imp_??1CandidateSet#Dxc##QAE#XZ) referenced in function "public:
void __thiscall ExampleDA::sendDiagnosis(void)"
(?sendDiagnosis#ExampleDA##QAEXXZ) D:\Dropbox\Work\Visual Studio
2010\Projects\DXC11\DXC11\ExampleDA.obj DXC11
I'm stuck with this problem for quite some time now and I'm desperate for help!
Thanks a lot
You need to add the specific lib file to the libraries list, so that the linker can search it for the symbols you're missing.
The task says to add that particular .lib to the list of libraries that get linked to your code. Without saying that this library should be linked, the implementation for the functions defined in its headers is not available to the linker and you get that unresolved external symbol.
In VS, you can add something to the linked libraries list either through a #pragma comment or in the project settings:
// at the top of main.cpp, preferrably
#pragma comment(lib, "the_lib_name.lib") // .lib optional
You can have different libraries for debug and release with simply surrounding the #pragma comment in an #if block:
#ifdef NDEBUG // release
#pragma comment(lib, "the_lib_name.lib")
#else // debug
#pragma comment(lib, "the_lib_named.lib") // most debug libraries end with a 'd'
#endif
And for the project settings you can do so with
[Project] -> <Project Name> Properties (or Alt-F7) -> Configuration Properties
-> Linker -> Input -> Additional Dependencies
Just add the_lib_name.lib at the front (followed by either a space or a semi-colon ;). Make sure you add the correct library for the active project configuration (debug / release).
I'm working on a solution file (VS 2005) which contains multiple projects.
There are two projects of my concern right now - one called core and another called log.
The core project is the startup project and the log project has core ticked in its project dependencies.
I have two files in core project - AB.h(declarations) and AB.cpp(definitions)
Many other cpp files from the core project refer to AB.h and has no issues finding the definitions in AB.cpp.
Now comes the issue. I have a cpp file called CD.cpp in the log project which requires referring to AB.h. I have added the include directory of AB.h to both the core and log projects (AB.cpp also resides in same folder)
In addition the log project has $(OutDir) in its "Additional Library Directories" parameter in the Linker part of project settings. Also have added "core.lib" to the Additional Dependencies field in Properties->Linker->Input
The core project compiles into a dll but there is also a core.lib in the same folder amongst other junk. Solution compiled as the Release version.
In CD.cpp, when I right click the #include "AB.h" line, it takes me to .h file in the core folder. So far everything is fine. However when I try to compile the solution, the log project does not build properly, showing these two linker errors.
log.obj : error LNK2001: unresolved external symbol "class myNamespace::myClass myInstance" (?myInstance##3VmyClass#myNamespace##A)
log.obj : error LNK2001: unresolved external symbol "bool infFlag" (?infFlag##3_NA)
The class is part of an h file included in AB.h (instance declared in AB.cpp and included as extern in CD.cpp. infFlag is declared in AB.cpp and declared in CD.cpp as extern.
What do I do to let log build properly? Thanks
OK. You guys need more details. Sure.
One Solution file. Multiple Projects.
[Core]
includes AB.h and AB.cpp
-AB.h
--includes EF.h from external lib (functions from this lib is working properly for files within the same core project).
--declares some functions
-AB.cpp
--defines those functions which was declared in AB.h
-some other cpp files which can use those functions from AB.h without issues
[/Core]
[Log -> Project Dependencies -> Core]
-No h files
-CD.cpp
--requires AB.h to work. Is included with a #include command and its linked properly (I can right click and click "open file" to open the real .h file)
--uses functions from AB.h
[/Log]
Hopefully this will better let you guys understand the project structure in my solution.
Issue comes when compiling Log project. It always comes up with a link error for any references to functions in AB.h saying "unresolved external symbol". I guess this comes because it cannot find the definitions for the functions declared in AB.h (probably because it is a different project). Since log is dependent on core, and core will have compiled as of then, I added in $(OutputDir) to Library directories (both core and log build into the same directory) so that it can find core.lib and also added "core.lib" to "Additional Dependencies" under Input tab under Linker (in project properties).
So there you go. Any ideas?
In addition the log project has $(OutDir) in its "Additional Library Directories" parameter in the Linker part of project settings.
Probably wrong. It should be that dir where "core.lib" resides, the $(OutDir) is where the log will be put.
The class is part of an h file included in AB.h (instance declared in AB.cpp and included as extern in CD.cpp. infFlag is declared in AB.cpp and declared in CD.cpp as extern.
So where are definitions?