简体   繁体   中英

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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM