How to link and include PhysX 4.0 Extensions Library? - c++

I am including the PhysX 4.0 SDK into my C++ opengl project, but I cannot use anything from the PhysX Extensions library like PxDefaultErrorCallback or PxDefaultMemoryOutputStream because I need to include the Extension library first. The problem is I cannot find the PhysXExtensions32.lib and its DLL in any folder of the PhysX SDK that I have compiled myself.
I could find a static library called PhysXExtensions_static_32.lib, but when linking against this library I get this error:
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in file.obj.
Is there a way I can get the Extension libaray as Multithreaded-Debug-DLL (/MDd) instead of a Multithreaded (/MT)?
I link against these libraries:
- PhysX_32.lib
- PhysXCommon_32.lib
- PhysXCooking_32.lib
- PhysXFoundation_32.lib
I redistribute these DLL files:
- PhysX_32.dll
- PhysXCommon_32.dll
- PhysXCooking_32.dll
- PhysXFoundation_32.dll
- PhysXGpu_32.dll

Got an answer on a duplicate of this question on the PhysX 4 Github repo and it is working now:
https://github.com/NVIDIAGameWorks/PhysX/issues/115

Related

I can't build project with quickfix [duplicate]

I have some problems with pjsua2.lib. I can't build this in QT. I added the following libraries:
INCLUDEPATH += "$$DIRECTX_PATH\Include"
INCLUDEPATH+="$$SIP_PATH\pjsip\include"
INCLUDEPATH+="$$SIP_PATH\pjlib\include"
INCLUDEPATH+="$$SIP_PATH\pjlib-util\include"
INCLUDEPATH+="$$SIP_PATH\pjnath\include"
INCLUDEPATH+="$$SIP_PATH\pjmedia\include"
INCLUDEPATH+="$$SIP_PATH\pjsip-apps\src\pjsua\pjsua_app.h"
INCLUDEPATH+="$$SIP_PATH\pjsip\src\pjsua-lib\pjsua_acc.c"
LIBS += "$$DIRECTX_PATH\Lib\x86\dsound.lib"
LIBS += "$$DIRECTX_PATH\Lib\x86\dxguid.lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\WS2_32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\Ole32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\WSock32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\IPHlpApi.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\NetAPI32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\AdvAPI32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\Gdi32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\User32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\odbccp32.lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\odbc32.lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\msvfw32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\Version.Lib"
LIBS+="$$SIP_PATH\lib\libpjproject-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsip-core-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsip-simple-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsip-ua-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsua2-lib-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsua-lib-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjlib\lib\pjlib-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjlib-util\lib\pjlib-util-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjmedia\lib\pjmedia-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjnath\lib\pjnath-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libbaseclasses-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libg7221codec-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libgsmcodec-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libilbccodec-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libmilenage-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libportaudio-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libresample-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libspeex-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libsrtp-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjmedia\lib\pjmedia-audiodev-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjmedia\lib\pjmedia-codec-i386-Win32-vc8-Debug.lib"
but these errors show up whenever I try to build the application:
pjsua2-lib-i386-Win32-vc8-Debug.lib(endpoint.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
I think the problem comes from the compiler, but in any way, I can't seem to solve it
This means that the library you are linking to has been build with a different version / variant of the CRT (C Runtime). You either need to rebuild the library or set the runtime library version + variant (release/debug, DLL/static) in your projects properties to the same settings as all the libraries you are linking to.

Is there a way to include both WICTextureLoader and DDSTextureLoader without 'redefinition' errors?

I'm trying to load a DDS texture. For that, I'm using DDSTextureLoader11 provided by DirectXTex. I already am using another texture loader from the same library - WICTextureLoader11.
The problem is, I don't get errors with WICTextureLoader11, however I do get errors either when including only DDSTextureLoader11, or when I use both of them.
This is some of the errors I get when I include both or only DDSTextureLoader11:
/WICTextureLoader11.cpp:51:17: error: redefinition of 'SetDebugObjectName'
/WICTextureLoader11.cpp:273:17: error: redefinition of 'MakeSRGB'
/WICTextureLoader11.cpp:747:17: error: no matching function for call to 'SetDebugObjectName'
/DDSTextureLoader.h:156:35: error: redefinition of default argument
I first thought that it was because both WICTextureLoader and DDSTextureLoader contain same functions, so when including both they "overlap" (i.e. compiler detects redefinition).
I'm using a batchfile to compile my project, where I link against both DirectXTex and DirectXTK. I also tried to include DDSTextureLoader, but without success: I've read the GitHub page of the DirectXTK's DDSTextureLoader, where I include <DDSTextureLoader.h> that gives me a link error, which I guess is related to the incorrect call of the function CreateDDSTextureFromFile, so right now I'm trying to find a way to make the right call to the function.
Edit: no, it seems like I'm making the right function call. The wrong thing is that I'm trying to include DDSTextureLoader.h, but it also wants DDSTextureLoader.cpp. However, the errors occur when I include DDSTextureLoader.cpp, such as:
'DDSTextureLoader.cpp': call to 'BitsPerPixel' is ambiguous -> 'DirectXTex.h' or 'DDSTextureLoader' error: redefinition of 'SetDebugTextureInfo', previous definition in 'WICTextureLoader'.
I think, what I need is to include the .cpp file, but somehow get rid of the errors.
Edit2: So far, I tried to get rid of DirectXTex (I don't remember why I even needed it), and I've included WICTextureLoader.cpp and DDSTextureLoader.cpp. I downloaded and built the DirectXTK library, then included #pragma comment(lib, "directxtk.lib"). Now, the weird thing is: when I compile with Clang++, it doesn't throw any errors (but the program crashes after a second-long gray screen), however when I compile with cl (through vcvars64), I get fatal error LNK1104: cannot open file 'directxtk.lib'.
Edit3: Wait, I don't even know why I even need the directxtk.lib. So I removed it, and it compiles, but nothing works. I thought I needed that static library to resolve external symbol errors when trying to include the header (XXXTextureLoader.h), instead of the source (XXXTextureLoader.cpp).
Edit4: Wait,wait,wait. I think, I'm going crazy. Now, if I include only WICTextureLoader.cpp (and remove DDSTextureLoader.cpp), it gives me this error: (directxtk.lib) mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease'. I don't know why I did that, but I'm crazy now, I blindly brute-force my way through resolving this cursed issue. Why can't I just throw both headers in my directory and just simply include them? Is there a way to do so? What should I do? Why doesn't DirectXTK/Tex pages on GitHub give a step-by-step guide to how to use these things? The examples drive me crazy!
Please, help me resolve this what seems to be a simple issue.
Edit5: The last thing that I tried is to include DDSTextureLoader.h and WICTextureLoader.h, and use directxtk.lib, but it gives me these errors:
directxtk.lib(DDSTextureLoader.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main-3dacd8.o
directxtk.lib(pch.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main-3dacd8.o
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
I don't use VS, so I don't know how to use /NODEFAULTLIB.
You have three choices for loading DDS and other image files with WIC:
Use DirectXTex (the library)
Use DDSTextureLoader/WICTextureLoader (the standalone versions)
or use DirectX Tool Kit (the library).
There's no reason to use more than one of them in the same program, and it's going to conflict if you try. See this post.
Unless you are writing a texture processing tool, or need support for the plethora of legacy DDS pixel formats, using DirectX Tool Kit is usually the simplest. The tutorials for DirectX Tool Kit covers this pretty well.
The error you are getting indicates something much more basic to using Visual C++. The DirectXTex, DirectXTK libraries build using the recommended "Multithreaded DLL" version of the C/C++ Runtime (i.e. /MDd and /MD).
The error indicates your program is building with "Statically linked" version of the C/C++ Runtime.
See Microsoft Docs
You didn't mention what compiler toolset you are using other than "not VS".
See directx-vs-templates for a bunch of 'basic device and present loop' samples. If you don't use VS, there are 'CMakeLists.txt' available on that site.
I was confused once again with DirectXTex and DirectXTK.
I resolved the issue by:
Removing DirectXTex
Downloading DirectXTK
Running the DirectXTK_Desktop_2019_Win10 solution
Changing the Build to Release and x64
Opening the properties
Finding the option Runtime Library
Choosing Multi-threaded /MT
Building the solution
In my source file, I include:
#include <WICTextureLoader.h> and #include <DDSTextureLoader.h>
I can now link to the generated static library directxtk.lib, without getting errors.
Plus. If there are people who want to use things like /NODEFAULTLIB:library, but you don't use cl or Visual Studio, you can use the #pragma directive in your source file like this:
#pragma comment(linker, "/NODEFAULTLIB:MSVCRT")

Need to use release library in cmake debug build

I have generated a release library using CMAKE that needs to be kept proprietary. I plan to put header files into an include directory and library files into a lib directory.
The CMAKE line used to generate the library is:
add_library(Ethernet STATIC ${eth_srcs} $<TARGET_OBJECTS:EthernetBootloader>)
There are separate Visual Studio solutions for generating a library and running a control panel that uses the library. Running the Control Panel in debug mode only works with a debug library. If the Control Panel compiles and runs in debug mode and the library was built in release mode I get several errors that look like:
Ethernet.lib(ethernet.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
Ethernet.lib(ethernet.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
I am beginning to write a "ethernet-config.cmake" file that contains:
set(ETHERNET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
set(ETHERNET_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/Ethernet.lib")
string(STRIP "${ETHERNET_LIBRARIES}" ETHERNET_LIBRARIES)
and the CMakeLists.txt looks something like:
set(Ethernet_DIR "C:/MotorController/public")
find_package(Ethernet REQUIRED)
include_directories(${ETHERNET_INCLUDE_DIR})
target_link_libraries(ControlPanel ${ETHERNET_LIBRARIES})
How do I use a release library in a Visual Studio 2015 Windows 7 64-bit debug application? I think I need to adapt my CMakeLists.txt for the debug application but haven't figured it out.

LNK2038 Error when adding Boost lib into Qt project

I'm working on a C++ application in Qt and got to a point where the compiler is at least able to open the included boost library files. Now I get:
LNK2038: mismatch detected for 'runtimelibrary' value
'MTd_StaticDebug' does not match 'MDd_DynamicDebug' in main.obj
So, I have skimmed other threats about this issue. The compiler version of Qt (msvc 2014) matches the one of the lib-files (i.e. libboost_filesystem-vc140-mt-sgd-1_61). This is my include for the debug-version (haven't tried release yet because that one has other issues to be solved later).
win32:CONFIG( debug, debug|release ) {
# debug
LIBS += -L$$PWD/boost/bin.v2/libs/filesystem/build/msvc-14.0/debug/address-model-64/link-static/runtime-link-static/threading-multi/ -llibboost_filesystem-vc140-mt-sgd-1_61
LIBS += -L$$PWD/boost/bin.v2/libs/filesystem/build/msvc-14.0/debug/address-model-64/link-static/threading-multi/ -llibboost_filesystem-vc140-mt-gd-1_61
LIBS += -L$$PWD/boost/bin.v2/libs/system/build/msvc-14.0/debug/address-model-64/link-static/threading-multi/ -llibboost_system-vc140-mt-gd-1_61
}
Now, it seems that there might be something wrong with the runtime settings (/MD, /MT) but - tbh I have no idea how to check that or fix it.

Boost filesystem linking issues

I'm trying to link Boost filesystem into my VS project. I built the boost libraries and when I include filesystem.hpp in my project I'm getting the following error:
Error 1 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in App.obj E:\SourceControl\zombiegame\ZombieGame\Projects\Windows\libboost_filesystem-vc120-mt-1_58.lib(operations.obj) ZombieGame
This is talking about the boost libraries having MD_DynamicRelease while my app has MT_StaticRelease. So I thought this was boost automatically linking for me since it's showing that it's using libboost_filesyste-vs12-mt-1_58.lib, but I think that's the shared version and I want to use the static version. So at the top before I include filesystem.hpp I added:
#define BOOST_FILESYSTEM_NO_LIB
To stop boost from automatically adding the shared lib and then I added the static lib to the linker but it still acts like it's using the shared lib. What am I missing here?