• Uncategorized

About c# : Why-OR-Tools-doesnt-load-in-CLinux

Question Detail

I have a simple program in C# that uses OR-Tools 9.2.9972 on Ubuntu 21.04 but even after copying the shared libraries into the bin folder, it returns that the library was unable to be loaded. I tried the command dotnet add package but the error remains.

Unable to load shared library ‘google-ortools-native’ or one of its dependencies.

Any idea how to add these shared libraries into the project?

using System;
using Google.OrTools.LinearSolver;

public class SimpleLpProgram
{
  static void Main()
  {
    Console.WriteLine("Starting");

    Solver solver = Solver.CreateSolver("GLOP"); // linking error

    Variable x = solver.MakeNumVar(0.0, double.PositiveInfinity, "x");
  }
}

Project file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <LangVersion>8.0</LangVersion>
    <TargetFrameworks>net6.0</TargetFrameworks>
    <EnableDefaultItems>false</EnableDefaultItems>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
    <!-- see https://github.com/dotnet/docs/issues/12237 -->
    <RollForward>LatestMajor</RollForward>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AssemblyName>Google.OrTools.SimpleLpProgram</AssemblyName>
    <Version>9.2.9972</Version>

    <!-- Nuget Properties -->
    <Description>Simple App consuming Google.OrTools package</Description>

    <!-- Pack Option -->
    <IsPackable>true</IsPackable>
    <Title>Google.OrTools.SimpleLpProgram v9.2.9972</Title>
    <PackageId>Google.OrTools.SimpleLpProgram</PackageId>
    <PackageTags>sample</PackageTags>
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>

    <!-- Signing -->
    <SignAssembly>false</SignAssembly>
    <PublicSign>false</PublicSign>
    <DelaySign>false</DelaySign>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugType>full</DebugType>
    <Optimize>true</Optimize>
    <GenerateTailCalls>true</GenerateTailCalls>
  </PropertyGroup>

  <!-- Dependencies -->
  <PropertyGroup>
    <RestoreSources>../../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="SimpleLpProgram.cs" />
    <PackageReference Include="Google.OrTools" Version="9.2.9972" />
    <PackageReference Include="Google.OrTools.runtime.linux-x64" Version="9.2.9972" />
  </ItemGroup>
</Project>

Question Answer

Wow! the cause was a mismatch for glibc… I updated Ubuntu to 21.10 which comes with glib 2.34 and it worked.

Before:

$ ldd google-ortools-native.so

./google-ortools-native.so: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /home/daniel/.nuget/packages/…/libortools.so)
    linux-vdso.so.1 (0x00007fffd39b6000)
    libortools.so => /home/daniel/.nuget/packages/…/libortools.so (0x00007fabb3407000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fabb31dc000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fabb308e000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fabb3073000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fabb2e85000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fabb2e69000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fabb530a000)
$ ldd --version

ldd (Ubuntu GLIBC 2.33-0ubuntu5) 2.33
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.