Anyone know if there is a sample out there on how to create a shared library using VS2019 extension or manually using cmake?
and then create another c++ app to call it.
after c++ app works, then I like to use c#(.net core) to call this library.
Shared Library function:
int getval()
{
return 123;
}
Main testapp.cpp:
extern int getval();
int main()
{
int testval;
testval = getval();
printf("testval = %d!\n", testval);
return 0;
}
unfortunately, I am a newbie to your platform.
I need a little bit more detail, how do you:
Create a project using the library code sources as an initial base.
I use the VS 2019 IDE, I only see way to create library, after I put in the source, no button is enabled to build it. so no exename anywhere.
What I mean by the first step is create a Torizon C/C++ application. This is the only project template that is supported by our extension. If you create any other project template our extension will not work.
In this project copy and paste your shared library code into the main code body. This is what I mean by creating a project where the library code is your base.
Then copy your application binary to the project. This is so that when the project is built and deployed as a container, both your shared library and the application that uses it gets deployed. However currently our extension will only build one thing at a time which is why we copy the application pre-compiled. I suppose you could go the other way and start with the application source and then copy the library binary into the project, but either way.
Then via the Torizon project properties there should be a propety called exename you want this to be your application binary. Otherwise by default it will try and execute your shared library binary which obviously wouldn’t be correct.
This article shows how to use our extension on a decent sized project as well as do basic functions like changing the project properties of the extension and such.
linker have error since it doesn’t know about my library functions in testapp. I’m suppose to link this testapp to the shared library .so
just want to make sure you understand what I’m trying to do.
testapp calls a library function in mylib
testapp.cpp
#include <cstdio>
extern int getval();
int main()
{
printf("hello from testapp\n");
printf("%d\n", getval());
return 0;
}
1>Compiling sources: 1>main.cpp
1>Linking objects
1>/usr/lib/gcc-cross/aarch64-linux-gnu/10/…/…/…/…/aarch64-linux-gnu/bin/ld
: error :
/home/build/testapp/obj/x64/Debug_debian_arm64v8_bullseye/main.o:
in function main': 1>C:\VulcanEmbedded\testapp\main.cpp(9): error : undefined reference to getval()’ 1>collect2 : error : ld
returned 1 exit status 1>Done building
project “testapp.vcxproj” – FAILED.
and I can’t findd anything in the project setting to set the .so
also, we really don’t have a .so, because mylib project only have .out
and in mylib project, I can’t found the exename you refer to, I see program under debug
mylib.cpp in mylib project:
#include <cstdio>
int getval()
{
return 123;
}
int main()
{
printf("hello from mylib!\n");
return 0;
}
Issue was discussed more in-depth in an external call.
But for the rest of the community here. It was decided that this is probably easier to do in the VS Code extension as the process is more readily customizable there.
In the above example we modify the default build steps to build a library that the main application relies on. Something similar can be done for other use-cases as well.
Though eventually we hope to have a simpler example of this that can be generally applied.