I need help with creating a dynamic library for linux using Visual Studio Linux Development Extension. I have never developed for linux but I did my research and I'm stuck. I can't figure out what is wrong.
I'm using this extension. https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/
So here is what I did. first I created an empty linux project in visual studio called foo. I added a class called foo.h and foo.cpp.
foo.h
#ifndef foo_h__
#define foo_h__
extern void foo(void);
#endif
foo.cpp
#include <stdio.h>
void foo(void)
{
puts("Hello, I'm a shared library");
}
in the Configuration Properties I changed the Configuration type from Application(.out) to Dynamic Library(.so)
in C/C++ -> Command Line -> I added "-fpic".
I saved and I built the project.
This is my output
1>------ Rebuild All started: Project: foo, Configuration: Debug x64 ------
1> Cleaning remote project directory
1> Validating architecture
1> Validating sources
1> Copying sources remotely
1> Starting remote build
1> Compiling sources:
1> foo.cpp
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(1190,5): warning MSB8012: TargetExt(.so.1.0) does not match the Linker's OutputFile property value (.0). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(1191,5): warning MSB8012: TargetName(libfoo) does not match the Linker's OutputFile property value (libfoo.so.1). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1> Linking objects
1> foo.vcxproj -> C:\Users\Fantasy-Desk\Desktop\test\foo\foo\bin\x64\Debug\libfoo.so.1.0
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
After that I created a Linux Console Application which has a main.cpp file.
#include <stdio.h>
#include "../foo/foo.h"
int main(void)
{
puts("This is a shared library test...");
foo();
return 0;
}
In the Configuration Properties -> Linker -> Input -> Additional Dependencies I add "projects/foo/bin/x64/Debug/libfoo.so.1.0".
When I build and run the application I get an error inside the linux terminal that says
"error while loading shared libraries: projects/foo/bin/x64/Debug/libfoo.so.1.0.
"cannot open shared object file name: no such file or directory"
I can't figure this out and google is no help.