Jump to content
  • Advertisement
Sign in to follow this  
FantasyVII

Create a dynamic library in linux and link to it using Visual Studio Linux Development

This topic is 734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Your linker input has "projects" in it, while the resulting path for the library doesn't. The paths don't match.

Simple check: Does a file "projects/foo/bin/x64/Debug/libfoo.so.1.0" exist where you expect it? Edited by Endurion

Share this post


Link to post
Share on other sites

alright, I added "./" before "projects" and now it works fine. my bad. 

so now the path looks like this "./projects/foo/bin/x64/Debug/libfoo.so.1.0". 

 

So now that everything works like it should, can someone explain what are these two warnings mean? and is there a way to fix them?

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).

Share this post


Link to post
Share on other sites
Well, did you read the right part of the warnings?

They say exactly what the cause is; that the mismatch might cause problems later on; and the second part of the message starts with "to correct this...".
Did you check those properties if they do match %(Link.OutputFile)?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!