Including c libraries in the custome code section of Simulink - c

I'm trying to include Csparse from SuiteSparse in to Simulink.
I've included the header ch.h and the directory of the c-functions in the custom code section.
If I call the function cs_compress over code.ceval I get this error:
cs_compress.obj : error LNK2019: unresolved external symbol cs_spalloc referenced in function cs_compress
Test2_sfun.mexw64 : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe"' : return code '0x460'
Stop.
The function cs_spalloc I presume is called from a library since there exists no cs_spalloc.c. The function is however defined in the header file as:
cs *cs_spalloc (csi m, csi n, csi nzmax, csi values, csi triplet) ;
Am I right to presume it is called from a library?
And if so where do I find the library in a format to include in to the custom code section in Simulink?

I found the c- functions cs_spalloc online, and just copyed it. Now it works.

Related

Access Golang code from a C project in Visual Studio 2019

I have a C project in Visual Studio 2019 and I would like to use certain functions written in Go within it.
I have a test file called ctest.go which has the following contents:
package main
import (
"C"
"fmt"
)
//export printInt
func printInt(x int) {
fmt.Printf("Hello from go: %d", x)
}
func main() {}
I'm generating a static library with this command:
go build -buildmode=c-archive ctest.go
I end up with two files, ctest.a and ctest.h which I include in my VS project. I include ctest.h in my code and immediately get these errors:
identifier "__SIZE_TYPE__" is undefined
expected a ';'
expected a ';'
The generated header file contains the following lines which caused it:
typedef __SIZE_TYPE__ GoUintptr;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
I replaced __SIZE_TYPE__ by size_t and just commented out the _Complex lines to stop the errors.
Now my VS project compiles while including the header file. But as soon as I try to use my go function like this:
printInt(5);
I get 2 warnings followed by 6 errors:
Warning LNK4078 multiple '.text' sections found with different attributes (60600060) AWO F:\AWO\AWO\ctest.a(go.o)
Warning LNK4078 multiple '.text' sections found with different attributes (60600060) AWO F:\AWO\AWO\ctest.a(go.o)
Error LNK2019 unresolved external symbol __imp___iob referenced in function __cgo_preinit_init AWO F:\AWO\AWO\ctest.a(000005.o)
Error LNK2001 unresolved external symbol __imp___iob AWO F:\AWO\AWO\ctest.a(000006.o)
Error LNK2001 unresolved external symbol __imp___iob AWO F:\AWO\AWO\ctest.a(000007.o)
Error LNK2019 unresolved external symbol _fprintf referenced in function _x_cgo_sys_thread_create AWO F:\AWO\AWO\ctest.a(000005.o)
Error LNK2001 unresolved external symbol _fprintf AWO F:\AWO\AWO\ctest.a(000007.o)
Error LNK1120 2 unresolved externals AWO F:\AWO\Debug\AWO.exe 1
This is where I'm stuck. I'm not sure what I'm doing wrong or should be doing differently to properly use the library generated with go.
project properties -> linker -> input -> additional dependencies
legacy_stdio_definitions.lib;%(AdditionalDependencies)
add source code
C
FILE* __cdecl __iob_func(void)
{
FILE _iob[] = { *stdin, *stdout, *stderr };
return _iob;
}
C++
extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

Where is the IID of IVpnManagementAgent defined

I'm trying to create an object of IVpnManagementAgent but I can't seem to find where the IID (IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent) of it is defined so I can instance RoGetActivationFactory as it seems it requires me a second parameter of REFIID.
Also I saw this example but as I'm using C - I can't use __uuidof.
Weirdly enough the msdn sample seems to omit this parameter.
The problem is if I compile this code:
#include <roapi.h>
#define COBJMACROS
#include <windows.networking.vpn.h>
(main)()
{__x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent *pVpnMan;
IClassFactory *pCF; RoInitialize(RO_INIT_MULTITHREADED),
RoGetActivationFactory(0,
&IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent,
&pVpnMan);}
Like this: cl rmousevpn.c /link RuntimeObject.lib windows.networking.lib
It gives me unresolved:
rmousevpn.obj : error LNK2019: unresolved external symbol IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent referenced in function main
rmousevpn.exe : fatal error LNK1120: 1 unresolved externals

CppUtest example link error

--------------------Configuration: AllTests - Win32 Debug--------------------
Linking...
AllTests.obj : error LNK2001: unresolved external symbol "int externTestGroupMockDocumentation" (?externTestGroupMockDocumentation##3HA)
AllTests.obj : error LNK2001: unresolved external symbol "int externTestGroupEventDispatcher" (?externTestGroupEventDispatcher##3HA)
Debug/AllTests.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
AllTests.exe - 3 error(s), 0 warning(s)
Why do I get these errors and how can I resolve them?
Do you have these lines in your AllTests.cpp?
IMPORT_TEST_GROUP(MockDocumentation)
IMPORT_TEST_GROUP(EventDispatcher)
If you do, you also need to have these test groups defined in you build:
TEST_GROUP(MockDocumentation)
TEST_GROUP(EventDispatcher)
James
wondering if you got over this issue,
I am facing the same issue although I have
IMPORT_TEST_GROUP(my_test_group);
in AllTests.cpp and properly defining
TEST_GROUP(my_test_group) {};
in my_test.cpp as per Mr. Grenning's advice.
Notice I have been able to get it to compile by applying either one of the following workarounds:
1- Add the cpp file containing the function definition to the UnitTest project. Or..
2- Have the function definition in the header file (typical if your function is a template)
I don't know if either/any of the suggestions is correct (so not claiming an answer yet), however, I mention my workaround here in the hope others might find it helpful.
N.B. I have CppUTest-3.6 configured with visual studio 2010 according to "D:\cpputest-3.6\docsWalkThrough_VS21010.docx"
Hasan

Fatal errorLNK2019 and LNK1120 while use LZOpenFile?

I am Working on Windows Vista, and have the following code:
#include <windows.h>
// ...
INT vint = NULL;
vint = LZOpenFile(lpFileName,lpReOpenBuf,wStyle);
When I build my program, it fails with linking errors:
fatal error LNK2019: unresolved external symbol _LZOpenFileW#12 referenced in function "int_stdcall LZOpenFile(wchar_t *,struct _OFSTRUCT *,unsigned short)" (?LZOpenFile##YGHPA_WPAU_OFSTRUCT##G#Z)
fatal error LNK1120: 1 unresolved externals
Help me to resolve this problem... Thanks in Advance....
You need to link against Lz32.lib. Make sure you have this lib listed in your linking options.
thank you, Matthew Talbert
first select properties from solution explorer (right click),select linker options and then select command line options ,insert Lz32.lib on that place ......now build succeed without any fatal error......
To link against Lz32.lib in MS Visual 2008:
Project --> Properties
Then see in
--> Linker
--> Input
And in Additional Dependencies simply add Lz32.lib

What library should be included to use TransparentBlt?

What library should be included to use TransparentBlt?
This is VC98 (Visual Studio 6) linking to the Gdi32.lib. (Other GDI functions such as BitBlt link as expected), and the compilers compiles with out error or warning.
Even though the Gdi32.lib is included, yet the linker returns this error:
mtcombo.obj : error LNK2001: unresolved external symbol __imp__TransparentBlt#44
C:\Work\Montel\Targ2_12\guitest.exe : fatal error LNK1120: 1 unresolved externals
What am I missing?
AFAIK, you will need the Msimg32.lib
http://msdn.microsoft.com/en-us/library/ms532303(VS.85).aspx
Msimg32.lib
FYI you can search the functions on http://msdn.microsoft.com/library and at the bottom it will tell you what library you need.

Resources