Using Libraries / error LNK2001

May 11, 2011 at 3:23pm
Hi,
I am trying to use the NOMAD (an optimization software) library in C++. I am using Visual Studio 2010.

I got error LNK2001 error. I have #include "nomad.hpp". Can anyone help me what I am missing?

In the NOMAD handbook, the following is written.
If you are using Visual C++, your programs will not link with this version of the library and you must compile the library yourself. I don't know what it means? Can someone help please?
May 11, 2011 at 3:27pm
The reason you are getting this error is that as well as including the header file (these are often mostly declarations), you must link the corresponding libraries (which usually contain the actual implementations/definitions of functions, etc.).

However, from what you say it look like you cannot link the existing library binaries. This probably means that you have to take the source files of the NOMAD library and compile/build them yourself, just you like would one of your own C++ projects.

Perhaps you can find instructions on how to do this on Google? Is there a makefile with the NOMAD files?
May 11, 2011 at 7:11pm
Thx Xander312. The code that I am using is one of the example codes coming with the NOMAD installation so I do not think the problem is with the definitions of corresponding libraries.

Yes there is a makefile, though I tried to use it using cmd but could not make it worked. After NOMAD installation, nomad.hpp and nomad.cpp files are saved. I tried to compile it with a C++ project, it was successfully compiled but what else I should do? I also saved the nomad.hpp to the source code's directory. Still did not work...
May 11, 2011 at 8:05pm
So you have compiled the NOMAD project? In that case you need to:
1) Find the library files resulting from this build (.lib extension for MSVC)
2) Add these files to your link libraries list in your active project: "Project -> Properties -> Configuration Properties -> Linker -> Input" and then click "Additional Dependencies", and finally click the arrow on the right and "Edit"

Then you can add additional link libraries - add the NOMAD ones.

You will also need to add the library paths to your VC++ directories.
May 12, 2011 at 2:10pm
I exactly did what you suggested. Still, I have the same error: LNK2001. :( Any other suggestion?
May 12, 2011 at 3:15pm
Could you provide the whole text of the error message, rather than just the error code?
May 12, 2011 at 4:51pm
There are bunch of error codes, I guess I have a problem about calling the library. One of the error coes is
error LNK2001: unresolved external symbol "void_cdeck NOMAD:end(void)"(? end@NOMAD@@YAXXZ).

As I said I think the issue is not related with NOMAD but I am missing somehing basic about using the libraries.
May 12, 2011 at 4:57pm
It looks like you have included the NOMAD header files directly.

Are you linking the NOMAD library files (.lib for Visual Studio).

Note that from what you said above, you may have to create these library files yourself.
May 12, 2011 at 5:20pm

Are you linking the NOMAD library files (.lib for Visual Studio).


Just like you said in
So you have compiled the NOMAD project? In that case you need to:
1) Find the library files resulting from this build (.lib extension for MSVC)
2) Add these files to your link libraries list in your active project: "Project -> Properties -> Configuration Properties -> Linker -> Input" and then click "Additional Dependencies", and finally click the arrow on the right and "Edit"

Then you can add additional link libraries - add the NOMAD ones.

You will also need to add the library paths to your VC++ directories.
I linked the library file (nomad.lib). It exists in NOMAD folder. I did compile the nomad.hpp and nomad.cpp files. To create the library files, do I need to do anything else?
May 12, 2011 at 5:39pm
I shouldn't think so. Are you sure that the lib files are the ones you compiled yourself, and not the ones that came with NOMAD?
May 12, 2011 at 9:18pm
I am not sure. I might use the ones that came with NOMAD. Other than that lib file, I have only cpp and hpp files in a folder called src. I compiled those but I do not know if they are the right ones. What should I look for, in order to compile to get lib files?
May 13, 2011 at 6:42am
Where did you get NOMAD, on a disc or as a download?

Provided you have a backup copy of it, I suggest deleting any .lib files (or .dll) files within one copy of the NOMAD files.

Then get CMake: http://www.cmake.org/
At the top, in CMake, enter the source files directory as your NOMAD root directory. And set the binaries directory to your NOMAD directory + "/build/".

At last, click configure and set your generator to "Visual Studio 10". Finally, click "Generate". Then go to the /build/ subdirectory of the NOMAD directory and find the Visual Studio *.sln file. Open it, and build the solution (possibly in debug and release configurations - you'll have to see NOMAD documentation for details).

Then link to the versions of the NOMAD binaries which are created within this /build/ folder.

I hope this helps.
May 13, 2011 at 1:48pm
Xander

I did what you suggested. now got a cmake error in Cmake: directory does not appear to contain CMakeLists.txt.
May 13, 2011 at 2:20pm
Okay, then. Have a look at the NOMAD files and see if there is a CMakeLists.txt file anywhere. if you find one, you should probably provide that directory to CMake as the source files directory.

If you can't then it looks like you can't use CMake with it.
May 13, 2011 at 6:27pm
There is no CMakeLists.txt but the problem is solved thanks to Xander314 and Yusuf from Hemosoft. Here is the solution:

After creating the libraries using the cpp and hpp files, I defined the location of the created library file as additional library directories. (Project properties >> Configuration properties >> Linker >> General) Also, the created library file (lib file) is defined as additional dependencies. (Project properties >> Configuration properties >> Linker >> Input).

When I first tried it did not work. Then I installed the Service pack. Then it worked. Thanks again.
May 13, 2011 at 6:38pm
Glad you got it sorted :)

PS: You can now mark this thread as "solved" so that forum members know there no more help to be provided.
Topic archived. No new replies allowed.