Ubuntu: How to use new generated libraries in order to run the executable again and debug the code

  .so, c++, compilation, g++

Problem Description

I found an error in a library that i’m using in my C++ code. The following is the description of the OS that i’m using along side where the header of the library is located and the .so libraries. inside /usr/lib/ we have: libFoo.so --> libFoo.so.2020

 - OS: `Ubuntu 20.04`
 - Header(.h): `/usr/include/fooapi.h`
 - Library(.so): `/usr/lib/`

I compiled a new library with a different version of the code, but same functions. The compilation generated new libraries libFoo.so.2021 and libFoo.so.2021.debug. Both of the new libraries are placed in the same folder:/home/bob/workspace as the source code. I tried to replace libFoo.so.2020 with libFoo.so.2021 in /usr/lib. But, it didn’t work and I got a lot of compilation errors.


Compilation

g++ -g test_foo.c -o foo_test.out -lfoo. But in here lfoo is referencing the old library libFoo.so.


Source Code

#include "fooapi.h"
int main() { int x = FooCompute(); return 0;}

Question

How can I tell g++ that I want to use the new library libFoo.so.2021 or libFoo.so.2021.debug without going to /usr/lib and doing the dirty replace old library thing.

Source: Windows Questions C++

LEAVE A COMMENT