Compiling an Octave mex file through Visual Studio 2013 - c++

I just switched to Octave from Matlab and would like to continue to compile mex-files as a DLL through visual studio.
I have a project which creates a dll and exports the mexFunction as previously. I also include the mex.h file found in Octave but I have trouble linking.
Currently I get a linking error stating:
error LNK2019: unresolved external symbol __imp_mexPrintf referenced in function mexFunction
I understand why but I don't know what to include to resolve this issue.
Can anybody help?
Thanks
Henrik

The files are found in:
C:\Octave\Octave-3.8.2\lib\octave\3.8.2
and I used liboctave.dll.a and liboctinterp.dll.a

Related

Linking C library with a C++ dll: "unresolved external symbol __mingw_vsnprintf"

I've built a C++ Windows dll using Visual Studio - a.dll.
I used Cygwin and MinGW (x86_64-w64-mingw32-gcc) to build a helper C library - helper.lib.
The dll needs to use the helper library, so I modified Visual Studio project, tried to link with the library, but I get:
error LNK2019: unresolved external symbol __mingw_vsnprintf referenced in function inquiry where inquiry is one of the functions inside helper.lib.
What am I doing wrong?

unresolved external symbol fabs, cos, sin

EDIT2: problem solved with adding libucrt.lib to link options
I'm trying to compile resource only DLL-file with VisualC++ 2017 compiler. Here is my command line:
cl test.cpp /link /dll /noentry "E:\CXGE\build\Debug\CXGE.lib"
Test.cpp contains some basic functions and math operations. But for some reason I can't use any of c++ math functions like std::sin, std::cos and std::abs in my DLL file because of this linking error:
test.obj : error LNK2019: unresolved external symbol fabs referenced in function "double __cdecl abs(double)" (?abs##YANN#Z)
Can someone say which libraries do I need to link to fix these errors? I'm on Windows 10, using Visual C++ 2017 compiler
EDIT: I am using X64 Native tools command prompt for VS 2017
C Runtime libraries are missing. Either include them or try to compile using VS command prompt.
These functions are in the math library. Under Linux, you'd typically link this just by adding '-lm' to the compilation line. I'm not sure of the equivalent for VC++, but hopefully it's something similar.

How to use a library in other c++ code?

I'm trying to use a library in my code.
But as I'm new in c++, I couldn't do that without any errors.
First I copied library in my main file and then in my main code I just included .h files.
When I ran it, it gave me some errors like:
error LNK2019: unresolved external symbol "public: __cdecl library"
The library contains .cpp and .h files of functions.
I'm doing it in Visual Studio 2012.
What should I do to use this lib?
Assuming you are using this library, The documentation to make an installation on Visual Studio is located here.
If this is your first time with C++ then this is a very complex project to start with... Using a library is a complex process as every single one has a diferent installation method.

Finding Reasons for Linking Errors in Visual Studio

I'm in the process of porting one of my project to an existing framework I've been developing. As a result I have two project, one that's the original I developed and then the ported one.
The problem I'm having is that the new project doesn't link. The error is "... unresolved external symbol ..." where the symbols should be defined in a library that's linked together with the project. By using VS command line tool dumpbin.exe I confirmed that the symbols said to be missing are in the library. The original project works fine, only by removing the library from the Linker->Input->Additional Dependencies do I get the same errors for that project.
Are there other reasons for "... unresolved external symbol ..." or am I simply not linking the library?
Details
The library in question is OpenCL.lib and the errors are "error LNK2019: unresolved external symbol _clBuildProgram#24 referenced in function ..." for all OpenCL API calls. Using the technique described in Tools for inspecting .lib files? I get the symbols for each function as one would expect.
Okay, figured it out. The library I'm linking with is only for x64 architectures, switching to that platform got it working.
Would've liked a more descriptive error from VS but what can you do...

Unresolved external symbols in compiling 32 bit application in Windows 64

So I am trying to compile legacy app from 32 bit to 64 bit..
I re-compiled all of the libs it used and made it look into WIN SDK6.0A x64 bit for libs..
I am using:
Visual Studio Professional Edition 2008
Visual C++
dotNet Framework 3.5 SP1
Windows Server 2008R2
Windows SDK is 6.0A
Everythings finally coming up but I am getting these weird undefined symbol errors:
error LNK2019: unresolved external symbol InterlockedDecrement referenced in function ...
error LNK2019: unresolved external symbol InterlockedIncrement referenced in function ...
error LNK2019: unresolved external symbol GetModuleBaseName referenced in ...
error LNK2019: unresolved external symbol EnumProcessModules referenced in ...
error LNK2019: unresolved external symbol EnumProcesses referenced in ...
error LNK2019: unresolved external symbol GetProcessMemoryInfo referenced
The problem is these are all win stuff from SDK.
InterlockedDec and InterlockedInc are coming from kernel32.lib
GetModuleBaseName, EnumProcessModules, EnumProcesses,GetProcessMemoryInfo are in psapi.h but also kernel32.lib or psapi.lib
I checked C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\x64 and both libs
kernel32.lib and psapi.lib are there.
It definitely looks up the libs at right spot. I turned on /VERBOSE:LIB
and it points to the correct folder.
So I am really confused why isnt it finding them.
Any ideas???
Thanks
So I finally figured it out, kinda...
It wasnt finding psapi.lib
In Project->Linker->Additional dependencies instead of just saying psapi.lib
I gave full path to it and it worked...
not really sure why it failed to find it before but oh well...
This is very long shot (and I don't really believe this is it) but maybe the headers are not properly guarded with extern "C" for c++ compilation? Are you including system headers or just declaring the functions yourself?
Can you post your compile and link command lines, and any #def's in your code?
Does this happen if you make a simple project from scratch that only calls one of those methods?
For the record: Same problem, different solution;
I had an entry for the directory
psapi
added in the list of
Linker/General/Additional Library Directory
This resulted in the usage of the old VS2005 platform sdk psapi.lib (it only had x86, no x64 version).
After removing the entry the correct lib from the installed WinSDK x64/psapi.lib is used now.
So keep an eye out for mixings/ordering of old & new SDKs!
Obviously the full path will also work but might be a problem when you use the project on multiple machines.
In my case(migrate from VS2008 to VS2012), issue solved after adding psapi.lib in Linker->input->Additional Dependencies in VS 2012.