Integrating two Projects of same Solution DLLs - c++

I have one dll project (A) of plugin in visual studio solution. This means i have a solution with one dll project.
I want to make another project (B) which caters to some specific functionality of dll project. Final output is dll. So dll project (A) is my main project. new Project B uses some of the headers of the dll project (A).
How do i link them together ?
I tried adding references of A in B but that failed. When i just add header files in "Additional Include Directory" it gave linker errors because it could not find the cpp or definitions.
error LNK2019: unresolved external symbol
I also have problem in setting the output format for B. should it be .lib ?
Would "Add Existing Items" is the only solution ?

Related

Linking a DLLs in visual studio 2013

I've already looked for solution, without a success.
I need to use a DLL supplied by third parties on Visual Studio 2013(running on (x64) Windows 10).
On machine there are both OpenCV 3.0.0 and OpenCV2.410 installed and working.
The DLL's author has provided a .lib file and He says that in order to use this DLLs in your project, you need to put some others OpenCV's dlls in the project folder( I've tried to put these DLLs in every project folder[yes I know, it has no sense, but after a lot of tries i've lost my patience])
What he supplies is an .dll and an example project( that doesn't work for me because it needs OpenCV2.1 and there are instructions needs to be translate in newest version [and I prefered don't translate nothing]).
The errors in this example project are of this kind:
error LNK2001: unresolved external symbol
fatal error LNK1120: unresolved externals
The most of them are caused by the miss of OpenCV2.1, that I don't want to install, because I'll have to use it on a program using with OpenCV 3.0.0.
In the example project folder there are:
The upper mentioned .dll
A .lib file
The header file .h
These DLLs: cv210.dll, cxcore210.dll, highgui210.dll, ...(eg. cv210d.dll)
What I've done is this:
A folder called "lib" where I insert all .dll, .lib, .h files.
Put the "lib" folder in Project properties>linker> General> Additional Library Directories
Writing the .lib file in properties>linker> Input> Additional Dependencies
Put the 'lib' pathproperties>C/C++>Additional Include Directories[I know, this has no sense too]
I get these kind of errors:
error LNK2001: unresolved external symbol
I've tried #pragma comment(lib, 'file.lib') way too.
Someone can help me?

linking error for not being able to link header file to cpp file correctly

I have two projects in one solution. When I try to access a function of one project's from another one I get error LNK2001: unresolved external symbol. But the linking error only happens when the function is declared in the header file but defined in the corresponding cpp file. If the function is defined in the header file than the error does not occur. Also calling function from same project doesn't give any error. Only calling from another results on linking error.
EDIT: I am using visual studio 2010. I don't know if its worth mentioning that the function which is being called is in a project that outputs a lib file and the one which is calling that function outputs a exe file.
If you define the function in the header file, the compiler will see the function implementation when you build the .exe project and compile a copy of the function code directly into your .exe project. When it is the linker's turn during the build, nothing is missing so the linker is happy and you won't get an error message.
If you define the function in the .cpp file, the compiler will not see the function implementation. It will thus put a reference to the function (i.e. the external symbol) that needs to be resolved later on when it is the linker's turn during the build. To make the linker "see" the external symbol, you need to link your .exe project against your .lib project. Once you have established this link dependency, the linker will be able to find the external symbol and resolve the reference to the function that was earlier generated by the compiler. Because you have a .lib project, which is a static library project, the linker resolves the symbol by grabbing the code for the function from the .lib file and places a copy of the code into your .exe file.
So much for the theory. Now the simplest way to make your .exe project link against your .lib project probably is by adding a reference:
In the .exe project's settings, select the section named "Common Properties" at the top of the section list.
You should now see a list of references that the .exe project has. The list is probably empty.
Click the "Add new reference" button at the bottom of the dialog and add the .lib project as a reference
When you select the new reference in the list of references you will see a set of properties for that reference. Make sure that the property called "Link Library Dependencies" is set to true. This will cause the .lib project to be added automatically as an input to the linker when you build the .exe project.
If you build your .exe project, the linker error should now be gone.
Incidentally, by adding the project reference you have also told Visual Studio to build the two projects in the correct order if you build the entire solution: First the .lib project, then the .exe project.
It is the role of the linker to resolve unknown symbols.
Thus if projet A uses methods from projet B defined in the cpp file, you need to link A against B.
As stated, it would be fine to have more information about both projects, IDE (visual???)...

Unresolved external symbol when including MFC object library

I have an object file library that exists as a standalone VC++ project. I have a number of other completely separate VC++ solutions, and I would like some of them to utilise the classes included in this library.
I have added the project to a solution as detailed here: (See docs). I have followed all of the instructions but am still getting "unresolved external symbol" errors when trying to use the class.
Can anyone help?
Specifics:
The class library in question is an SQL access library. Inside there are two files, sql.h and sql.cpp. Pretty simple. That project compiles itself absolutely fine, so I know there is nothing wrong with that project. I was under the impression that to get the project included in an existing solution I had to:
Add the project to add the project to the solution
Add a reference to the project
Add the include directory
Add #include "sql.h" to the project
That is what I have done, to no success.
Please make sure the external library is linked into your project. It usually comes in a form of a .lib file (for example, sql.lib)
Go to Configuration Properties ->Linker and add your library to the "Additional Dependencies" list.

Linking DLL error visual studio

I walked through this tutorial and tried to recreate the example I get this error:
Error 1 error LNK2019: unresolved external symbol __imp__GetXyz#0 referenced in function _main app.obj app
If I download the source from the website and run the project in visual studio it works, but If I even copy the code from the original project in my own visual studio solution it still doesn't work. I guess it must be some project settings, I don't know. What do do?
You need to add the XyzLibrary.lib to your Linker settings within project settings.
You can also do it directly in code by using #pragma comment(lib,"xyzlibrary.lib") if you are using VisualStudio.
The reason why it works in the given sample without these 2 approaches is that in the solution file, the dependencies are set from XyzExe to XyzLib, and XyzProject has 'Link Library Dependencies' in Linker settings set to true. However, I am not too keen on this approach, as I don't like to store data important for building inside solution files (for larger projects, developer's solution files can differ from build system solution files)
Seems like you are missing some external library that needs to be linked in. Whatever provides the GetXyz function is missing.
Open the Solution that works, right click the project, Properties, Linker, Input, and check what their Additional Dependencies list up. You need to add the same to your own project.

C++ linking error unresolved external symbol

I have a project that includes files from a different project. I am getting linking errors...
"unresolved external symbol "public: _cdecl classA::classA(void"
(??()classA ##QEAA#XZ) referenced in function "class classA *_cdecl
functionB(char const*)" (?functionB##YAPEAVClassA##PEBD#Z)...
and other 125 errors of the same type (after the constructor, which is the error I just listed, every function from the class I use is mentioned in one of the link errors).
The path for including the files of the second project is included in my property sheet. That project, on its own, builds fine.
I have tried to add that project to my solution, and add it as a dependency. No help. I have tried to add the dll that it creates in the project - linker - input. No help.
In Configuration properties, the Runtime Library is set to /MTd.
I have even tried to add extern "C" in front of my include. No help.
I have tried to build them with Debug or Release, x64 or Win32. I prefer Release x64 but I'll take anything.
Could you please help me - tell me what am I doing wrong, or where to look to fix this problem ? Thank you very much.
When you build the project which yours depends on, it should produce both a lib and a dll. You need to link that lib with your project. See this thread for a screenshot of how to link the lib in your project.
I found out that my dependencies in the Link - Input were being removed by the fact that I didn't explicitly specify that I can have dependencies in the property sheet. After changing the property sheet, I finally was able to create a dll.