C++ - Unable to link in libyaml using Visual Studio 2019/CMake - c++

Attempting to link in libyaml (0.2.5) using Visual Studio 2019 Enterprise and CMake, as I have a cross-platform (Linux/Windows) project that uses this library. According to the documentation, this library should work in Windows 10. It links in just fine on Linux (64-bit machine).
I'm compiling it as a static lib, and it has no issue generating the .lib file. I've copied it to the appropriate location that I'm linking in from my CMakelists.txt, as well as the header.
When I link it in from my project on Windows:
ts.lib(yamlparser.cxx.obj) : error LNK2019: unresolved external symbol __imp_yaml_parser_initialize referenced in function "public: bool __cdecl YAMLParser::parse_cfg(void)" (?parse_cfg#YAMLParser##QEAA_NXZ)
ts.lib(yamlparser.cxx.obj) : error LNK2019: unresolved external symbol __imp_yaml_parser_set_input_file referenced in function "public: bool __cdecl YAMLParser::parse_cfg(void)" (?parse_cfg#YAMLParser##QEAA_NXZ)
ts.lib(yamlparser.cxx.obj) : error LNK2019: unresolved external symbol __imp_yaml_parser_scan referenced in function "public: bool __cdecl YAMLParser::parse_cfg(void)" (?parse_cfg#YAMLParser##QEAA_NXZ)
This is what I'm doing on the CMake side - the very same thing I'm doing to link in my GoogleTest libraries on both Linux and Windows:
if (UNIX)
...
...
else()
set (MY_LIB_DIR "C:/mylib/lib")
set (MY_INCLUDE "C:/mylib/include")
set (YAML_LIB "${MY_LIB_DIR}/yaml.lib")
set (VCPKG_LIBRARY_LINKAGE static)
endif()
include_directories(${MY_INCLUDE})
add_library(ts
...
...
)
add_executable(myexec main.cxx)
target_link_libraries(myexec ts ${YAML_LIB})
VS isn't giving me many clues here except that there's a linkage problem that I can't quite figure out.
Any advice on how I can debug this or what the problem may be?

The __imp was the clue that my code was trying to include the library dynamically... Opening up yaml.h, I noticed that it tries to export from DLL unless YAML_DECLARE_STATIC is defined. Defined this in CMake and my issue is resolved.

Related

Including Lua in VS2015 C++ Project

I would like to integrate Lua into my current C++ application I build with VisualStudio 2015 (x64 mode).
I grabbed a simple Lua wrapper from here, and the Lua binaries for windows x64 from here (the lua-5.1.5_Win32_dll14_lib.zip one).
Next, I added the include and library path to the project preferences. Works so far in the IDE. However, when I try to compile the code it throws 24 errors (like these first two):
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_close" referenced in function ""public: __cdecl LuaScript::~LuaScript(void)" (??1LuaScript##QEAA#XZ)".
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_gettop" referenced in function ""public: void __cdecl LuaScript::clean(void)" (?clean#LuaScript##QEAAXXZ)".
which tells me next to nothing. Seems that the linker is unable to find the library but the includes are working and the path to library is set, too. Any suggestions what I might have missed or should look into? Any hint would be appreciated!

How to build a static Clucene library to avoid any linker errors

I work with Windovs and I need to build a static CLucene library. I downloaded the latest source code and build them into Visual Studio 2010 Project through CMake-gui 3.4.3. When building I used a flag BUILD_STATIC_LIBRARIES = true. I successfully built two libraries: clucene-core-statics and clucene-shared-static. However, when I run the test project cl-test-static occurs a lot of linker errors. The same thing happens when I add these libraries in another test project.
Error Example:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: static wchar_t * __cdecl
lucene::queryParser::QueryParser::escape(wchar_t const *)"
(__imp_?escape#QueryParser#queryParser#lucene##SAPA_WPB_W#Z)
referenced in function "public: void __thiscall Main::Start(void)"
(?Start#Main##QAEXXZ) c:\Users\user\documents\visual studio
2010\Projects\TestClucene\TestClucene\Main.obj TestClucene
Does anyone have any experience in building static CLucene libraries?

Link errors with GraphicsMagick

I downloaded and compiled GraphicsMagick, 1.3.23, Q16, x64, StaticMT version. I had to convert the Visual Studio 7 solution generated by GraphicsMagick's build utility to Visual Studio 2015 format. I linked my project to CORE_DB_magick_.lib and CORE_DB_Magick++_.lib.
When the linker ran, it produced unresolved external symbols when linking InitializeMagick() and DestroyMagick()
1>wtd.lib(WebController.obj) : error LNK2019: unresolved external symbol __imp_DestroyMagick referenced in function "public: __cdecl Wt::WebController::~WebController(void)" (??1WebController#Wt##QEAA#XZ)
1>wtd.lib(WebController.obj) : error LNK2019: unresolved external symbol __imp_InitializeMagick referenced in function "public: __cdecl Wt::WebController::WebController(class Wt::WServer &,class std::basic_string,class std::allocator > const &,bool)" (??0WebController#Wt##QEAA#AEAVWServer#1#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_N#Z)
I can't understand why the symbols are not being linked. Any ideas?
Apparently, GraphicsMagick Static versions do not link properly.
What is your project type? I had a similar problem when trying to link the GraphicsMagick libraries to a DLL.
The clue here is that __imp is the function decoration for DLL imports, so you're trying to link with DLL functions.
The problem is that the header magick/common.h, when linked to a DLL project, reads the current configuration of the Visual Studio pre-processor environment to determine which mode the library is in, which is obviously wrong if you're trying to link static libraries into your DLL, for example. In this case, it defines MagickExport to __declspec(dllimport).
AFAIK this is a bug in the library. For proper static build support, magick/common.h needs to do something like read information from the magick/magick_config.h to determine what mode the library was actually built in and define MagickExport appropriately.
Since your library is statically linked, you can fix this by commenting out everything in the define:
#if defined(MSWINDOWS) && !defined(__CYGWIN__)
and replacing it with:
#define MagickExport
#define ModuleExport
#define MagickGlobal

Problems with SOCI

I'm trying to use the SOCI library for easy MySQL access but I'm stuck at installing the library.
What I've done so far is :
Made the project and compiled it with CMake
Linked my project to the lib/release directoy that's created after compilation.
Linked my project to the MySQL C Connector lib directory
and here are my additional include directories :
http://puu.sh/6qGNP.png
But somehow, when I compile the example program, I get a bunch of linker errors like these :
1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall soci::details::standard_into_type::~standard_into_type(void)" (??1standard_into_type#details#soci##UAE#XZ) referenced in function "public: virtual __thiscall soci::details::into_type::~into_type(void)" (??1?$into_type#H#details#soci##UAE#XZ)
1>main.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall soci::details::standard_into_type::post_fetch(bool,bool)" (?post_fetch#standard_into_type#details#soci##MAEX_N0#Z)
Where did I mess up?
From the documentation:
Required Client Libraries
The SOCI MySQL backend requires MySQL's libmysqlclient client library.
Note that the SOCI library itself depends also on libdl, so the minimum set of libraries needed to compile a basic client program is:
-lsoci_core -lsoci_mysql -ldl -lmysqlclient
This has always worked for me. If you want to link them from the build location a -L switch with the path to the libraries will need to be passed to the compiler.

unresolved external symbol _gluLookAt#72 referenced in function

I'm making a program using the glu library but when i compile i got this error:
1>opengl_3.obj : error LNK2019: unresolved external symbol _gluLookAt#72 referenced in function "public: void __thiscall OpenGLContext::setupScene(void)" (?setupScene#OpenGLContext##QAEXXZ)
I included GL/glu.h and checked if the lib and dll were present. (they are by default)
I'm using visual studio 2012.
Any idea where this error is coming from?
You are not linking to glu. Add glu to the libraries against which your program should be linked. A more detailed description can be found here.