Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:31:30+00:00 2026-05-16T21:31:30+00:00

I am using several P/Invokes under .NET. However, I want my library to work

  • 0

I am using several P/Invokes under .NET. However, I want my library to work both in Windows and Linux, preferably with the same binaries.

Since the native library I depend on is available on multiple platforms, I was hoping to just have them along with my managed library’s binaries.

Right now I’m using something like this:

[DllImport("/usr/lib/libMYLIBNAME.so.1")]

But this obviously only works for Linux. I was considering that I could possibly copy that binary from /usr/lib and distribute along with my application, so I could reduce the above to:

[DllImport("libMYLIBNAME.so")]

But this still is Linux-only.

Is there anyway to change the library name string so it’d look for libMYLIBNAME.so under Linux and MYLIBNAME.dll on Windows, or something very similar?

I would like to avoid anything that requires recompilation for each supported platform…

(Note: even better would be a solution that’d look for MYLIBNAME.dll on Windows and /usr/lib/libMYLIBNAME.so.1 on Linux, but this improvement is optional)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:31:31+00:00Added an answer on May 16, 2026 at 9:31 pm

    Two things

    1- DllImport without the extension
    This is supported on Windows, Linux and MAC and will import the appropriate library for the target platform.

    [DllImport("libMYLIBNAME")] - 
    

    2- The preffered option is to use the <dllmap/> which allows you to map an import library name to the target platform library name. So if on Windows you have a dll called mylib.dll and the corresponding Linux so is mylinuxlib.so.3.6.1 you can import this using the windows DLL name

    [DllImport("mylib.dll")]
    

    And add a configuration to the config to map this name to the Linux library name

    <configuration>
      <dllmap dll="mylib.dll" target="mylinuxlib.so.3.6.1" />
    </configuration>
    

    Read more Here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are several persons using the same login id on Linux Box. I want
Under Django 1.1.1, I am using several authentication backends such as social-registration for facebook
I'm using MEF to create several instances of the same export. I'd like to
I have built an application which simulates several clients using the same RMI service.
I am using several XBee Zigbee with some Arduino modules (or microcontrollers, Arduino is
In a webapp I'm using several filters and in one of the filter I'm
I am able to connect to an Oracle database using several tools, but am
I'm working on an application whihc supports using several DB vendors, with the table
I'm working on a Spring 2.0 project, without annotations. We're using several PropertyPlaceholderConfigurer beans
So I've been using Perl for several years now and I'm starting to dabble

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.