Direct2D Only Partially Linking in C++ Builder - c++

I've got a C++ Builder (Rad Studio Berlin) project setup to use Direct2d. Canvas drawing works just fine with the TDirect2DCanvas which would indicate Direct2D is linking properly. Everything renders smoothly. However, I need to use a matrix. I get linking error when I try to. For example, when try I:
canvas->RenderTarget->SetTransform(D2D1::Matrix3x2F::Rotation(15.0, D2D1PointF(100, 100)));
...I get the following linking error:
[ilink32 Error] Error: Unresolved external 'D2D1MakeRotateMatrix' referenced from C:\DP\TRUNK\SRC\CLIENTSIDE\APPLICATIONS\VIEWER\WIN32\DEBUG\MIMAGE.OBJ
C++ builder was supposed to already be setup to link against direct2d if I just include the headers. Can anyone help me link against the appropriate files in the C++ Builder way?

I found the solution from a different source. Here it is:
After some research, this issue has not been determined to be a bug.
For many of the standard Windows API functions, the IDE will add the correct library automatically so that the dependencies on the function references will be satisfied. With DirectX (which is somewhat uncommonly used), the IDE does not automatically supply the library which corresponds to the header file, so this is causing the unresolved linker errors.
The solution is to either (as I mentioned previously) add the D2D1.lib to the project, or statically reference it in code:
// as long as D2D1.lib is on the library search path, it should be found
#pragma comment(lib,"D2D1.lib")
Some developers add the above line of code to their headers and so all you need to do is include the header and all is well... the DirectX team did not do this and hence the unresolved linker errors.
Hope this clarifies the issue,

Related

Error LNK2019 when trying to use MRPT libraries as external dependency in VS2019 solution

I am implementing a SLAM-algorithm in Visual Studio 2019 where I want to use the ICP algorithm from the MRPT library for scan-matching.
I installed the MRPT library as 32-bit from source code using CMake. Problem is the error I'm receiving when building the solution (shown below). I assume it is because I have not added Additional Library Directories or Additional Dependencies for the Linker, because I can't find the .lib/.dll files anywhere. I tried installing the 64-bit precompiled binaries for Windows, where I found the .lib-files inside a lib-folder which does not appear when compiling manually with the source code - but can't use the same lib's because I need 32-bit (I tried linking to them, but the same error occurred in addition a bunch of warnings that library is 64-bit and target is 32-bit).
The code is pretty much exactly the same as the first example here, with (I believe) all necessary headers included.
The error produced (I also receive many more of the same error for every class I attempt to use from the library):
particle.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mrpt::poses::CPose2D::CPose2D(double,double,double)" (__imp_??0CPose2D#poses#mrpt##QAE#NNN#Z) referenced in function (function)
The quick question is: Shouldn't the .lib/.dll files be produced when compiling from source code as well? Or is there something embedded in the library so I don't need them, in which case there must be something else wrong?
The more complicated question is: If the missing .dll/.lib-files is not the problem, what could it be?
Sorry if I am missing any relevant information, this is my first post. Just let me know and I will provide.
Any help is greatly appreciated!

How to static link SpiderMonkey

I built SpiderMonkey v60 (the Firefox Javascript Engine) release like in the official documentation as a static library (I am trying to avoid dlls). After I added the import files and the js_static.lib to Visual Studio, linking errors occured.
I defined STATIC_JS_API (which should mean that mozilla should compile with the static library), but the only thing happened was the errors got more. I also tried to build SpiderMonkey differently and used mozjs-60.lib to it but nothing changed.
After adding STATIC_JS_API, I had compiling errors like "unresolved extern symbol _imp_timeBeginPeriod#4", "unresolved extern symbol _imp_timeEndPeriod#4", "unresolved symbol _imp_PR_GetOpenFileInfo" (altogether 7 unresolved symbols). I am using the hello world code from mozilla for SpiderMonkey 52, so this should be no problem, also the full building ran off without an error.

Linker error “contains invalid OMF record” 2

I'm working with Embarcadero XE8 C++ builder 32 bit.
I was adding a library to my program for solving the Unresolved external error.
When I added the library I got the error as in the title. So I searched the web and found this topic on stackoverflow:
Linker error "contains invalid OMF record"
As it says the COFF2OMF tool, CAN work. Sadly it didn't work for me, I give a 7mb library file, when I convert it with the tool it's only 41kb... so I guess the convertion failed. When I add the converted files to my program it just ignores it and still says the unresolved external error.
So how can I get my library working with my C++ builder?
A little background:
Libraries need to be compiled with the same kind of tool as the application you are trying to make, because every compiler does things a wee bit differently. Most libraries for Windows are compiled with the MVSC (Microsoft Visual Studio Compiler).
You're using the Embarcardero Compiler, which means that the MVSC libraries are incompatible (you may have noticed that ;)).
You have multiple options.
If you can, get the source of the library and compile it with your own compiler. That way the chance to succeed is the highest.
I may be mistaken since it's been a while, however I believe there's a tool called implib which takes the shared library (.dll) and generates an Embarcardero-style .lib from that for use in your project.
Use COFF2OMF to convert the static library. And even if the file size is strange, do at least try it.
Try the LoadLibrary function call. This one requires you to map the functions you need manually, however you get around using the .lib.
Good luck.

Linker error while building CUDA/C++ code

I get the following error while trying to build a CUDA/C++ code in Visual Studio 2012. I'm using CUDA v5.0
1> Generating Code...
1>LINK : warning LNK4044: unrecognized option '/MLd'; ignored
1>cublas_device.lib(kepler_sm35_gemm_wrapper.obj) : error LNK2019: unresolved external symbol __cudaRegisterLinkedBinary_59_tmpxft_00001040_00000000_8_kepler_sm35_gemm_wrapper_cpp1_ii_9402ff4f referenced in function "void __cdecl __sti____cudaRegisterAll_59_tmpxft_00001040_00000000_8_kepler_sm35_gemm_wrapper_cpp1_ii_9402ff4f(void)" (?__sti____cudaRegisterAll_59_tmpxft_00001040_00000000_8_kepler_sm35_gemm_wrapper_cpp1_ii_9402ff4f##YAXXZ)
Anybody has any idea of where the problem might be? I've tried googling around, but haven't found a solution for this as yet.
Thanks a lot!
This article shows information about what the /MLd linker option does. It essentially has to do with multithreaded libs being loaded and the configuration of your project.
Is your (Debug) project set up to link with the microsoft linker or nvcc? (The error messages appear to be coming from the microsoft linker.) You may want to look at this question
Device code and device libraries (that you are linking against) need to be linked with nvcc.
You need to link against the debug version of the CUDA library. You try to compile in Debug mode, but then you link against a library which seems not to have been built in debug mode. Thus it gets all messed up.
So you should either get the .lib file for the debug version, or build it yourself if you have the source code. Then you link your debug build with the debug .lib and same for release.
Also, it may help that you use the same version of the compiler to build all libs, otherwise you may run into name mangling issues (which could be also a potential cause for your problem). It happened to me after switching to a newer VS version: I had to recompile all the .lib I was linking against.
It looks like some sort of using a external (extern) variable that isn't defined. The code is required for further information
I was able to fix it! I was linking to cublas_device.lib which was referring to an unresolved external symbol. However, this lib file wasn't required by my project, so just removing it from the linked files worked! However, in Release mode this error wasn't happening - maybe because this part of the code in cublas_device.lib was in the debug section.
In any case, since it is not required by my project, removing it solves the problem.
Thanks a lot for all your replies!
I encountered the same issue, Changing the Configuration Type from "Dynamic library (dll)" to "Static library (lib)" worked for me.

Unresolved External Symbol for gluPerspective in CUDA project

Actually, I know it's a popular linking problem, which regularly can be resolved by adding #pragma(lib, "glu32.lib") or adding glu32.lib in Visual studio configuration.
However, my problem is strange and solutions above is useless.
I added some extra files containing OpenGL functions like gluPerspective and gluBuild2DMipmaps to the CUDA project, the VolumeRender, which is from CUDA SDK.
After compiling, I found those extra files would occur the Unresolved External Symbol error for glu functions. However, when I put these glu functions into the original Cpp file, it works fine.
I have ever tried two solutions above but useless. Could anyone give me a hint to solve this puzzle?
Finally I gave up. I tried to add the CUDA part into the OpenGL projects. It worked fine!