-1

I'm trying to modify VLFeat source code in particular the function vl_vlad_code in this file. Now, since it is the first time that I edit the source code of such a library, I started with something simple, like printing an Hello World! at the beginning of the fucntion:

void
vl_vlad_encode (void * enc, vl_type dataType,
                void const * means, vl_size dimension, vl_size numClusters,
                void const * data, vl_size numData,
                void const * assignments,
                int flags)
{
  printf("Hello World!");
...

Then (following this document convention):

  1. I removed the binary code with rm -rf VLFEATROOT/bin
  2. I recompiled the library with make in VLFEATROOT (with no errors)

However, when I call vl_vlad_code from my application nothing is printed. Notice that the library works fine in my C++ application, it just "ignores" my changes.

Just for completeness, I use Ubuntu 16.04 and this are the compiling options regarding VLFeat that I use in my Eclipse CDT project:

... -I/home/luca/vlfeat ... -L/home/luca/vlfeat/bin/glnxa64 ... -lvl

UPDATE: Following suggestions in the comments, I tried to write something to a file in this way:

void
vl_vlad_encode (void * enc, vl_type dataType,
                void const * means, vl_size dimension, vl_size numClusters,
                void const * data, vl_size numData,
                void const * assignments,
                int flags)
{
    FILE *f = fopen("/home/luca/file.txt", "w");
    if (f == NULL)
    {
        printf("Error opening file!\n");
        exit(1);
    }
/* print some text */
const char *text = "Write this to the file";
fprintf(f, "Some text: %s\n", text);

And no file is created!

justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
  • 3
    A blind suggestion: `printf("Hello World!");` --> `printf("Hello World!\n");` – Sourav Ghosh Dec 29 '16 at 18:27
  • Yeah I already tried that (actually it was the first version): it doesn't work :) – justHelloWorld Dec 29 '16 at 18:28
  • 1
    You are calling what where? Also you only mention that you recompile the library, do you also recompile/relink it with your application? – UnholySheep Dec 29 '16 at 18:29
  • Try calling `fflush(NULL);` after your `printf` – Basile Starynkevitch Dec 29 '16 at 18:29
  • 4
    Try to write to file. It could be that the library directs stdout somewhere else, or clears screen. I have worked with a graphics library, which directed stdout to a file. – VLL Dec 29 '16 at 18:31
  • @UnholySheep it's already written in the question: `vl_vlad_code` is the function called, it doesn't matter where or why (as I said the original version without the `printf` works fine). About the recompile/relink I cleaned and recompiled my application (through Eclipse CDT): same result, the `Hello World!` is not printed. – justHelloWorld Dec 29 '16 at 18:37
  • @BasileStarynkevitch I tried that also, nothing is printed anyway – justHelloWorld Dec 29 '16 at 18:37
  • @Ville-ValtteriTiittanen I'll try that – justHelloWorld Dec 29 '16 at 18:38
  • @Ville-ValtteriTiittanen ok, this is weird. Look at my **UPDATE** – justHelloWorld Dec 29 '16 at 18:49
  • What operating system on you running on? – merlin2011 Dec 29 '16 at 18:50
  • @merlin2011 wow, even OS? :D Ubuntu 16.04 – justHelloWorld Dec 29 '16 at 18:53
  • @Stargateur it is called: result from `vl_vlad_encode` are used later in the code and it works as expected, I'm 101% sure on it. I don't how, but it seems that it uses an old version of the library. – justHelloWorld Dec 29 '16 at 18:55
  • @justHelloWorld, Just so I know how to attempt to reproduce it as faithfully as possible. – merlin2011 Dec 29 '16 at 18:56
  • Just as info: I tried to write a random line in the `vlad.c` and `make` gives an error, as expected (so it actually recompile it) – justHelloWorld Dec 29 '16 at 18:56
  • I added the compiling option, but I don't see how could they be useful – justHelloWorld Dec 29 '16 at 19:00
  • Just because the library is being rebuilt doesn't mean your application is linking the version you're building. See if there are any other copies of the library on your system. – Rob K Dec 29 '16 at 19:06
  • 1
    I come back to say I am pretty sure that this function is not the one who is called. – Stargateur Dec 29 '16 at 19:08
  • Slightly off-topic: I suggest you to use `make clean` instead of manually deleting build files. – SplittyDev Dec 29 '16 at 19:18
  • @RobK you're the winner sir. As I explained in my answer, for some reason a copy of `libvl.so` was in `/usr/local/lib`, which is included in the project for other libraries that are used. Deleting it, the linker got the right version of `libvl.so` and the message was correctly printed! – justHelloWorld Dec 29 '16 at 19:26
  • Are you sure that `vl_vlad_encode` is actually called? You should compile with all warnings & debug info (`gcc -Wall -Wextra -g`) then use a debugger (like `gdb`) to check that. – Basile Starynkevitch Dec 30 '16 at 02:50

2 Answers2

2

It is possible that when you run the application you are actually linking with a system-wide installed library. As a test, try adding the directory where you built the library to the LD_LIBRARY_PATH environment variable then run your program.

From the command line you could do:

export LD_LIBRARY_PATH=/path/to/your/lib:${LD_LIBRARY_PATH}

If you are using an IDE, you should set the variable inside of its environment settings.

Paths in this variable will be searched before your system libs are searched.

You can always find out exactly where the libraries your executable is linking to are located by running:

ldd /path/to/your/executable
diametralpitch
  • 675
  • 3
  • 5
1

The problem was a copy of libvl.so in /usr/loca/lib. After deleting it the problem was solved and the message is correctly printed.

justHelloWorld
  • 6,478
  • 8
  • 58
  • 138