c++cvlfeat

printf() doesn't work in source code?


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!


Solution

  • 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