0

So finally I’m not able to help myself out by researching anymore. Hopefully you can help me. I recently decided to learn C++ in the context of my bachelor-thesis: My first aim is to read the pixel-values of a tiff-image with the libtiff-library. Yet, every call of a function of the library seems to break parts of my program.


Here’s the simple “HelloWorld”-Program, it works as it should:

#include "tiffio.h"
#include <iostream>
using namespace std;

int main() {
    cout << "Hello" << endl;
//  TIFF* tif = TIFFOpen("path to .tif", "r");
    return 0;
}

When I uncomment the second line in main(), the code still does compile without errors (except the warning that ‘tif’ isn’t used) and I can start the program as usual. Yet nothing gets printed into the console anymore. Not “Hello” nor any errors.


Any suggestions where the error could be? The code should be alright, I guess I messed something up during the setup of the library or so. Here’s what I did:

  1. I managed to set up eclipse (Mars, 32bit) for C++ and MinGW (32bit) on my 64bit Win7, then downloaded libtiff 4.0.4 and built it following this instruction.

  2. I created a new C++-project with the mentioned code and did the following adjustments in the project-properties:

    • Project->Properties->C/C++ General->Paths and Symbols->Library Paths-> Added “D:/… /tiff-4.0.4/libtiff/.libs”

    • Project->Properties->C/C++ Build->MinGW C++ Linker->Miscellaneous->Set Linkerflags to “-static-libgcc -static-libstdc++”

    • Project->Properties->C/C++ Build->MinGW C++ Linker->Libraries-> Set (-L) to “D:/… /tiff-4.0.4/libtiff/.libs” and (-l) to “libtiff”

I know the .tif is a valid file as I implemented parts of my program in C#, using the LibTiff.NET library by BitMiracle.

Thank you in advance!


Edit 1: The same error occures, even if TIFF* tif = TIFFOpen("path to .tif", "r"); is never called but written down in a dead part of the code. Debugging does not work either, the program seems to be terminated (exit value 0) before a single line is executed, without any error-reports.

JCh3ss
  • 43
  • 1
  • 1
  • 7
  • Well, either, 1) You built libtiff incorrectly. 2) Your main program is built with differing options than your libtiff library. 3) Libtiff has a bug in the first function call. So take your pick. Also, doing stuff like this for C++ takes a lot more experience to determine where errors are occurring than doing this in C# or .NET. For example, you could have debugged into the TIFFOpen function to see exactly what line breaks your program within that function. – PaulMcKenzie Jul 20 '15 at 22:26
  • It might both be that libtiff is built incorrectly and the main problem is built with other options. Yet the linked [tutorial](http://www.gaia-gis.it/spatialite-2.4.0/mingw_how_to.html#libtiff) was not too hard to follow. But I don't have the knowledge to tell. Debugging does not work, the program seems to be terminated before a single line is executed. – JCh3ss Jul 20 '15 at 22:51

1 Answers1

0

I had the same issue and managed to get rid of it.

I set up eclipse (Mars) for C++ and MinGW on my 64bit Win7, then downloaded libtiff 4.0.4 and built it following this instruction. After the build, I got two directories containing files:

  1. include

    • tiff.h
    • tiffconf.h
    • tiffio.h
    • tiffio.hxx
    • tiffvers.h
  2. lib

    • libtiff.a
    • libtiff.dll.a
    • libtiff.la
    • libtiffxx.a
    • libtiffxx.dll.a
    • libtiffxx.la

I also linked all include files and only the libtiff.a to my project and that solved it, ie, the other lines are now executed.

I hope, I helped with this post.