0

I'm trying to compile some mixed C++ and C code on a mac in the terminal for an image converter, and I'm running into several errors. The imager converter code is available here:

https://code.google.com/p/ptmconvert/

At first the c++ compiler was getting fussy about the fact that some of the files are in c++ and some are just in c, which I was able to fix using the conditional definition thing found here: How do I add Objective C code to a FireBreath Project?

That is, I just added #ifdef __OBJC__ ... #endif around the .h file that the main .cpp code imports.

However, I'm still getting two errors from another include, and I can't figure out if it's the same issue or a different one.

The verbose description contains two errors and a bunch of warnings:

ptmconvert.cpp:236: error: ‘stbi_load_from_memory’ was not declared in this scope
ptmconvert.cpp:239: error: ‘stbi_failure_reason’ was not declared in this scope

And the short errors are as follows:

ptmconvert.cpp:236:25: error: use of undeclared identifier
'stbi_load_from_memory'
            planes[p] = stbi_load_from_memory(reinterpret_cast<unsigned ...
                        ^
ptmconvert.cpp:239:17: error: use of undeclared identifier 'stbi_failure_reason'
            if (stbi_failure_reason())
                ^
ptmconvert.cpp:242:35: error: use of undeclared identifier 'stbi_failure_reason'
                ss << "(stb) " << stbi_failure_reason() << std::endl;
                                   ^
ptmconvert.cpp:326:53: error: use of undeclared identifier 'stbi_image_free'
        std::for_each(planes.begin(), planes.end(), stbi_image_free);
                                                    ^
ptmconvert.cpp:388:10: error: use of undeclared identifier 'stbi_write_png'
    if (!stbi_write_png("coeffH.png", ptm->width, ptm->height, 3, ...
         ^
ptmconvert.cpp:391:10: error: use of undeclared identifier 'stbi_write_png'
    if (!stbi_write_png("coeffL.png", ptm->width, ptm->height, 3, ...
         ^
ptmconvert.cpp:394:10: error: use of undeclared identifier 'stbi_write_png'
    if (!stbi_write_png("rgb.png", ptm->width, ptm->height, 3, &rgbdata[0], 0))
         ^
7 errors generated.

If it's the same issue, can I just add another conditional somewhere, perhaps in the stb_image.c file?

Ok, so commenting out the include was dumb. Don't do that, future readers. Now the error I'm getting is that some of the terms aren't defined:

Undefined symbols for architecture x86_64:
  "_stbi_failure_reason", referenced from:
      ptm_read(char const*, PTMHeader12*) in ptmconvert-g4SsIR.o
  "_stbi_image_free", referenced from:
      ptm_read(char const*, PTMHeader12*) in ptmconvert-g4SsIR.o
  "_stbi_load_from_memory", referenced from:
      ptm_read(char const*, PTMHeader12*) in ptmconvert-g4SsIR.o
ld: symbol(s) not found for architecture x86_64

Any help/suggestions would be most appreciated.

Community
  • 1
  • 1
AlexB
  • 3
  • 5
  • Try to add some random charactors which are illegal for the compiler to the place where the "not declared" functions declare in .h file. Check that the declaration is correctly included. – MIKU_LINK May 09 '13 at 03:40
  • Thanks for the suggestion, @MIKU_LINK. It's not changing the error at all. Does that mean that `#ifdef __OBJC__` is not registering objective-c and therefore not importing the other parts of the program? – AlexB May 09 '13 at 12:21

1 Answers1

0

Ok, so the reason the compiler is giving an error is that there is no makefile for the c++ program. There is, however, a cmakelists.txt, which gives instructions to a makefile creator called CMake: http://www.cmake.org/

To compile ptmconvert you need to install and run CMake in the directory with the cmakelists.txt, which will create a makefile. Then you can run make in the same directory and it will create the executable PTM converter.

To run the ptmconverter, just type ./ptmconvert yourPTMfile.ptm

AlexB
  • 3
  • 5