LNK2019 even if I included the lib

Pages: 12
Hi,

I create 2 solutions, one is supposed to be a library that I now need to use in the second solution. I followed all the steps I found online, so write the include header, add the path to the .lib file in the project properties > link >general and the name of the library in the input tab. I did a lot of researches and I couldn't find any other step than those to make it work. Just in case it might be relevant, the application I am making is a plugin for maya and i started from the hello world template in order to have everything configured for maya.

I am not even entirely sure what I could share to help you helping me, I mean, I can't obviously share the entire project... Is there anything that could help you?

Cheers,
Daniele Dolci

LNK2019 is not the important part of the error message. That's just saying it's a linker error as opposed to a compiler/syntax error.

A good start if you want help would be to provide the full error message. Try googling the exact error message along with the lib name you're trying to use + visual studio.
e.g. < "undefined reference to __blahbalhbalh" blablah.lib visual studio >
Last edited on
Hello dd95,
LNK2019 even if I included the lib

The answer is 42. https://www.youtube.com/watch?v=aboZctrHfK8

Without the actual error message I have no idea what it pertains to.

Without code I can not duplicate the error.

It may be possible to post the code that contains the problem.

Does your error come from creating the ".lib" file or trying to use it?

It took me several tries to create and figure out how to use it.

Andy
Hi,

So those are the errors messages:

1
2
3
4
5
6
7
8
Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK1120	2 unresolved externals	ddRbf	C:\Users\daniele\Documents\workspace\ddPlugins\ddRbf\x64\Release\ddRbf.mll	1	

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "public: void __cdecl ddMatrix::print(void)const " (?print@ddMatrix@@QEBAXXZ) referenced in function "public: virtual class Autodesk::Maya::OpenMaya20180000::MStatus __cdecl ddRbf::compute(class Autodesk::Maya::OpenMaya20180000::MPlug const &,class Autodesk::Maya::OpenMaya20180000::MDataBlock &)" (?compute@ddRbf@@UEAA?AVMStatus@OpenMaya20180000@Maya@Autodesk@@AEBVMPlug@345@AEAVMDataBlock@345@@Z)	ddRbf	C:\Users\daniele\Documents\workspace\ddPlugins\ddRbf\ddRbf.obj	1	

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "public: __cdecl ddMatrix::ddMatrix(class std::vector<class std::vector<double,class std::allocator<double> >,class std::allocator<class std::vector<double,class std::allocator<double> > > >)" (??0ddMatrix@@QEAA@V?$vector@V?$vector@NV?$allocator@N@std@@@std@@V?$allocator@V?$vector@NV?$allocator@N@std@@@std@@@2@@std@@@Z) referenced in function "public: virtual class Autodesk::Maya::OpenMaya20180000::MStatus __cdecl ddRbf::compute(class Autodesk::Maya::OpenMaya20180000::MPlug const &,class Autodesk::Maya::OpenMaya20180000::MDataBlock &)" (?compute@ddRbf@@UEAA?AVMStatus@OpenMaya20180000@Maya@Autodesk@@AEBVMPlug@345@AEAVMDataBlock@345@@Z)	ddRbf	C:\Users\daniele\Documents\workspace\ddPlugins\ddRbf\ddRbf.obj	1	


The ddRbf is the project I am trying to build now, ddMatrix is contained in the library called ddCMath.

The header includes are:
1
2
#include "ddMatrix.h"
#include "ddRbfKernel.h" 


They are not underlined in red and if I do right click I am able to open the header file (so I guess it means it is found).

As for the code, I am not sure how to provide an example without sharing the entire project... do you have an idea?

Thanks for the help!
- The header files provide needed user-facing definitions of objects and functions.
- The lib file contains the implementations of functionality that needs to be linked to. This is why it's specifically a "linker" (LNK) error and not just a normal compiler error.

So basically, what's happening is that it's not correctly linking the definitions provided to their implementations in the .lib file. So something is wrong with your project settings in that it isn't linking to your lib file, or it can't correctly find the information it needs in that .lib file.

I actually am not getting many results from google, seems like this library is pretty rarely used.
If it's an incompatible .lib file, it might be you have to build it yourself.

Not sure if I have time right now to test it out myself, but if this code is freely available to the public, would you be able to link the tutorial you're following? Also, what version of Visual Studio are you using?
Last edited on
Hi,

thanks for the reply! I am actually writing the library myself as it is for my thesis. I work in the field of computer graphics and in the last 3 years I have been studying computer engineering, but university was teaching java unfortunately and not c++, so I am basically self taught.

I guess it is very likely possible I did something stupid with the .lib file then, since I made it myself starting from my own code. I was using a windows application project and I changed the extension from exe to lib and a couple more of options as it was explained on google.

I am using visual studio 2017 and windows 10.

would you need just the solution file/projects or do you actually need the source code? Because of university policy I am supposed to keep the source code private until thesis is delivered to the university.

Cheers,
The project files should be enough, but if you can produce a version with most of the code stripped out, leaving only the empty function bodies, that would help.
Last edited on
Hi,

Here is the library project, I removed most of the methods from the code and left only the constructor and the print method that was causing issues. You can dowload it from here:

https://drive.google.com/open?id=1Gi7mKqvSHf8aTgSyXnT5FUE_TaG6VF9Q

I am figuring out how to strip things out of the other code since It is a bit more complex. it has to follow a certain template in order to be a maya plugin and everything is related to something else and as soon as I start to take out parts it won't compile anymore. Maybe it is easier to first try to compile that lib and see if it would work in an empty project?

Thanks for the help guys!
Hello dd95,

I finally found it.

I put this line of code #pragma comment(lib, "Name of Lib File.lib") Which I have in a header file, but I imagine that you could put it in "main" just as easy.

I believe there is a setting in VS I have missed, but this works for now.

Hope that helps,

Andy
Hi,

Thanks for the help. Just to be sure, do I need to add that line to the ddCMath project or to the other project using the lib? and I guess "Name of lib file.lib" should become just "ddCMath", right?

Cheers,
Hi,

I tried both options, adding that line of code in the project of the lib and in the project where I am using the lib but i keep getting the same errors. Can you explain more in detail what you did? Sorry but I am very new to c++ :S
Hello dd95,

Yes. You are mostly correct. You need the full file name with the extension.

My setup includes a header file which includes a header file with the line #pragma comment(lib, "ddCMath.lib") , ( as you would use it). I would try putting it in the file that contains "main". I think that should be enough.

Hope that helps,

Andy
Hi,

I actually don't have any file that contains "main", in order to have to plugin to work for maya you normally have to subclass and reimplement a template class (in this case MPxNode from autodesk https://download.autodesk.com/us/maya/2011help/API/class_m_px_node.html). What I have is an ddRbf.h and ddRbf.cpp, as well as a pluginMain.cpp which despite the name what it does is registering the plugin for maya. So i tried placing it in the only header file I have, but it didn't work. I leave below the incipit of the file so maybe you will notice some obvious error I might be doing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma comment(lib, "ddCMath.lib")
#ifndef DDRBF_H
#define DDRBF_H

#include <maya/MPxNode.h>
#include <vector>

class ddRbf : public MPxNode
{
public:
	ddRbf();
	virtual			~ddRbf();
	virtual void    postConstructor();

	static void*		creator();
	static  MStatus		initialize();
[...]
Last edited on
Hello dd95,

So far I have created and used only ".lib" file.

Using VS I created a static library, which of course puts the compiled in the same places as if it were a program.

Then I found where most of the library files are stored and added my library and added my library file. That was the tricky part because the sub-directory, as with the directories above it are marked as "read only", i.e., no write permission. Not that I remember all the steps, but somehow I figured out how to add the file.

After I figured that the program was not including the proper file at link time I found the #pragma comment statement and that worked for me.

You will most likely find the path where you want to store the file at is: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86", although you may find it difficult to add a file to most of these sub-directories as they are "read only", but it can be done.

Another thought I had is that you may need to add the absolute path to the file where it was created. I was thing of something like: #pragma comment (lib, LIBPATH + "ddCMath.lib") where "LIBPATH" is defined as const std::string LIBPATH{ "C:\Users\daniele\Documents\workspace\ddPlugins\ddRbf\x64\..." }. Not sure if that would be the correct path, but it would similar to get to where a ".exe" file would be stored for a normal program, and that is if I remember correctly.

I will see if I can create something to try and duplicate your problem.

Hope that helps,

Andy
Hi,

I think there might have been a misunderstanding. The project I have uploaded it is working fine and compiling, creating a .lib file in the project/Release folder.

The problem is I am trying to include that lib in a second project where I get those errors I posted in the beginning.

Cheers,
Hi Andy,

I tried all of the things you suggested but I am not even close to get it compiled. I tried to use the \VERBOSE option to see more info about the output and whether the lib is in the program files folders or in the project folder, it gets printed under the unused library. I also tried to change the include statement from

#include "ddMatrix.h"

to

#include <ddCMath/ddMatrix.h>

But not luck with that neither.

I really have no idea what is going on.
have you done a lib before?
maybe make a little program...
make a function that prints hello world on the screen and compile that to a library.
then make a main that can use it. See if you can get that working to unravel the process.
then see what you did differently in the real program and try to repeat the same process there.

typically its pretty much
1) compile the library file to some sort of .lib or .dll or .o or similar file.
2) use a .h that defines the stuff in the library you want to be able to use in your real program.
3) compile that, with it including the .h and having the library file added to the compile options (varies from compiler to compiler how, a flag and filename for commandline compiles, add to project in visual studio, whatever).
Hi,

I tried to create an empt windows desktop application, where I simply wrote:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include "ddMatrix.h"
#include <vector>

int main()
{
    std::cout << "Hello World!\n"; 
	std::vector<double> test = { 1,2,3,4 };
	ddMatrix t(test, 2, 2);
	t.print();
}


It works, and it compiles. so it has to do with the configuration of the second project, on which I have limited control since I started from a template file from autodesk. Which settings might be interfering with the lib not working?
Ok I managed to make a minimal example by copying that snippet of code inside the project that is not working.

So now the problem is: How to compile this https://drive.google.com/open?id=1GikU6r9PKD8erP0P5kxg5HPFHolXhL_g

Using the library generated by the project I shared few posts ago?

If I do that on a fresh project it works, if I do this on this autodesk template I get the errors. Thanks!
I have no experience with autodesk :( ... you can either google something like 'autodesk library problems c++' or you could cross compare the settings (even if you can't change them, you can at least look) to see if there is an issue. Things like this can take time and some head banging, trial and error, web searching etc. I wish I knew.

You have narrowed down what the problem is. Just have to keep doing that until you find it.
Last edited on
Pages: 12