Compiling a shader using c++ (LNK2019 Error) - opengl

I'm trying to create a simple Arnold Renderer shader using visual studio based on the tutorial below. https://support.solidangle.com/display/mayatut/Creating+a+shader
I have created a win32console application with the application type set to DLL and have added my include libraries and ai.lib to the linker input.
When I try to compile the shader I'm met with
Error 1: error LNK2019: unresolved external symbol __imp__AiNodeParamRGB referenced in function "void __cdecl Parameters(struct AtList *,struct AtMetaDataStore *)" (?Parameters##YAXPAUAtList##PAUAtMetaDataStore###Z) C:\Users\matt\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.obj ConsoleApplication2
Error 2: error LNK2019: unresolved external symbol __imp__AiShaderEvalParamFuncRGB referenced in function "void __cdecl Evaluate(struct AtNode *,struct AtShaderGlobals *)" (?Evaluate##YAXPAUAtNode##PAUAtShaderGlobals###Z) C:\Users\matt\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.obj ConsoleApplication2
Any help?

You're trying to link a 64-bit library (ai.lib) to create a 32-bit dll. In other words, the linker is complaining because it doesn't understand the ai.lib architecture. The mismatch between 64 and 32-bit architectures are causing the problem. If your system is 32-bit, you can't compile the shader. If you have a 64bit system, you can set VC++ to build and compile a 64-bit dll.
On the tool bar in VC++
click on Win32 (next to debug), and open the drop-down menu.
Choose configuration manager, and under platform drop-down menu, choose x64.
Clean and build again.

Related

How to build wxWidgets with Visual C++

I followed along with the instructions for building wxWidgets on windows. I opened up a VS2019 command prompt and ran this build command and it finished successfully.
nmake /f makefile.vc BUILD=debug TARGET_CPU=X64
Trying to use this in another project hasn't been going as good. I copied the minimal sample program and while it compiles, I get ~330 link errors (LNK2019+LNK2001).
These are my project settings:
Include paths: {wxdir}\include, {wxdir}\lib\vc_x64_lib\mswd
Lib paths: {wxdir}\lib\vc_x64_lib
Linker inputs (these are all the libs that were created): wxbase31ud.lib;wxbase31ud_net.lib;wxbase31ud_xml.lib;wxexpatd.lib;wxjpegd.lib;wxmsw31ud_adv.lib;wxmsw31ud_aui.lib;wxmsw31ud_core.lib;wxmsw31ud_gl.lib;wxmsw31ud_html.lib;wxmsw31ud_media.lib;wxmsw31ud_propgrid.lib;wxmsw31ud_qa.lib;wxmsw31ud_ribbon.lib;wxmsw31ud_richtext.lib;wxmsw31ud_stc.lib;wxmsw31ud_webview.lib;wxmsw31ud_xrc.lib;wxpngd.lib;wxregexud.lib;wxscintillad.lib;wxtiffd.lib;wxzlibd.lib
Global defines: WIN32;_DEBUG;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;_UNICODE;_WINDOWS;NOPCH;
Changing the linker inputs has no effect on the errors at all, even when I remove everything. So I think I must be missing some crucial part of the set up process.
Here are the first 5 of the link errors in case it helps:
error LNK2001: unresolved external symbol "protected: static struct wxEventTable const wxFrame::sm_eventTable" (?sm_eventTable#wxFrame##1UwxEventTable##B)
error LNK2001: unresolved external symbol "int const wxEVT_NULL" (?wxEVT_NULL##3HB)
error LNK2001: unresolved external symbol "class wxEventTypeTag<class wxCommandEvent> const wxEVT_MENU" (?wxEVT_MENU##3V?$wxEventTypeTag#VwxCommandEvent####B)
error LNK2001: unresolved external symbol "protected: static class wxAppConsole * (__cdecl* wxAppConsoleBase::ms_appInitFn)(void)" (?ms_appInitFn#wxAppConsoleBase##1P6APAVwxAppConsole##XZA)
error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler##3P6AXABVwxString##H000#ZA)
Edit: After inspecting some .lib files with dumpbin.exe I found out they are 32-bit. But I specified "TARGET_CPU=X64" in my nmake command. And the output lib folder was called "vc_x64_lib". Is there some other way of specifying x64 that I'm not aware of?
Edit 2: After using the 'x64 Native Tools' command prompt instead, nmake generated 64-bit libs. This had no effect on the link errors...
The simples solution is to install wxWidgets via vcpkg. I have done it today. You can then create a C++ - project (subsystem: Windows and not Console).

Visual Studio 2010 project builds fine using 32 bit, but get LNK2028 and LNK2019 errors when trying 64-bit. What could fix this?

I have a Microsoft Visual 2010 project that runs fine in the Win-32 compilation setting. I am running on Windows 10. I am trying to use the x64 to build for 64-bit but that is when I encounter the LNK errors (examples below):
error LNK2028: unresolved token (0A00015D) "extern "C" unsigned char __cdecl
UcanDeinitCan(unsigned char)" (?UcanDeinitCan##$$J0YAEE#Z) referenced in function
"public: unsigned int __cdecl CAN::DeConfigDev(void)" (?DeConfigDev#CAN##$$FQEAAIXZ)
CAN.obj
error LNK2019: unresolved external symbol "extern "C" unsigned char __cdecl
UcanDeinitCan(unsigned char)" (?UcanDeinitCan##$$J0YAEE#Z) referenced in function
"public: unsigned int __cdecl CAN::DeConfigDev(void)" (?DeConfigDev#CAN##$$FQEAAIXZ)
CAN.obj
error LNK2001: unresolved external symbol __imp___glewGenBuffers Patient_GPU.obj
I've attempted to change the /clr function, as well as the calling convention (_cdecl ...) in an attempt to follow other solutions related to the LNK errors but neither has worked. Is there a different way to fix these errors, or get a better idea of what they actually mean? Any help would be greatly appreciated. Thank you so much!
You're probably linking UCAN static library from somewhere. You need to make sure that in 64bit configuration, you link to 64bit .lib file.
First thing to check is Additional dependencies config and check what libraries are linked into the project.

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?

Compiling in VS2013: error LNK2001 using C++

I'm trying to compile my game with Visual Studio 2013. The game uses Box2D, but when compiling in Release mode the release Box2D.lib is giving errors. It works fine when compiling in Debug mode with the debug Box2D.lib.
I'm getting 135 errors, and mainly something like these three:
1>Box2D.lib(b2CollideEdge.obj) : error LNK2001: unresolved external symbol #__security_check_cookie#4
1>MyContactListener.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)"
(__imp_?_Winerror_map#std##YAPBDH#Z)
1>Box2D.lib(b2ContactManager.obj) : error LNK2001: unresolved external symbol _atexit
I have built the Box2D.lib's several times now, and I'm sure I'm linking to the right release and debug libraries.
I tried disabling the compiler flag /GS (Buffer Security Check), but that didn't help.
For building the Box2D.lib and when compiling the game I use the flag Multi-threaded DLL (/MD) for runtime library.
EDIT: I got rid of the errors "#__security_check_cookie#4" when I linked with the library "bufferoverflowU.lib". Still, 133 errors remain.
You probably disabled linking of default run-time libraries in linker options. Right-click on the project and go to properties. Under Linker->Input set an option Ignore All Default Libraries to No.