1

I need to include my Exiv2 extension in my project using Makefile. I succeeded to run it directly through terminal with:

g++ -std=c++11 test.cpp -I/usr/local/include -L/usr/local/lib -lexiv2

My original Makefile (it works) important part:

COMPILER_FLAGS      =   -Wall -c -O2 -std=c++11 -fpic -o
LINKER_FLAGS        =   -shared
LINKER_DEPENDENCIES =   -lphpcpp -lopencv_core -lopencv_imgproc -lopencv_highgui \
                        -lopencv_ml -lopencv_video -lopencv_features2d \
                        -lopencv_calib3d -lopencv_objdetect \

Now I have to run a program that uses Exiv2 with a Makefile. Now I'm trying to customize the Makefile, tried

COMPILER_FLAGS      =   -Wall -c -O2 -std=c++11 -I/usr/local/include -L/usr/local/lib -fpic -o
LINKER_FLAGS        =   -shared
LINKER_DEPENDENCIES =   -lphpcpp -lopencv_core -lopencv_imgproc -lopencv_highgui \
                        -lopencv_ml -lopencv_video -lopencv_features2d \
                        -lopencv_calib3d -lopencv_objdetect \
                        -lexiv2 \

Doesn't work, output of make is:

[root@localhost psdk4]# make
g++ -Wall -c -O2 -std=c++11 -I/usr/local/include -L/usr/local/lib -fpic -o metacopy.o metacopy.cpp
metacopy.cpp: In member function ‘int Params::copyMetadata(int, char**)’:
metacopy.cpp:50:9: error: ‘AutoPtr’ is not a member of ‘Exiv2::BasicIo’
         Exiv2::BasicIo::AutoPtr fileIo(new Exiv2::FileIo(params.read_));
         ^
metacopy.cpp:50:33: error: expected ‘;’ before ‘fileIo’
         Exiv2::BasicIo::AutoPtr fileIo(new Exiv2::FileIo(params.read_));

...

It means that it doesn't find the Exiv2 methods, how to customize my Makefile?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Tomer Barak
  • 49
  • 1
  • 4
  • I don't see how makefile has anything to do with it. If the compiler cannot find something, then it is not there, and makefile cannot help --- unless it is somehow conditionally compiled, but we have no information about it and can say nothing without seeing the code. – n. m. could be an AI Aug 19 '20 at 11:51
  • I was saying that I succeeded compiling a program that uses Exiv2 with: g++ -std=c++11 test.cpp -I/usr/local/include -L/usr/local/lib -lexiv2 so it can be used properly, now my Makefile needs to include flags and dependencies in a correct way – Tomer Barak Aug 19 '20 at 11:59
  • "a program that uses Exiv2" doesn't tell me much. In what way does it use Exiv2? Does it use Exiv2::BasicIo::AutoPtr? – n. m. could be an AI Aug 19 '20 at 12:29
  • Just because a test program works doesn't mean different code will work. If you cut and paste make's compile line to your shell prompt and run it and you _don't_ see those errors, then we can conclude the problem is in the makefile somewhere. If you DO so those errors (which I'm sure you will) then the problem is either in your code (maybe you forgot an #include) or else the arguments you're passing to the compiler are still not right. Once you get it to compile from the command line you can fix your makefile. – MadScientist Aug 19 '20 at 12:41
  • BTW as a general rule it's a bad idea to be doing development and running make as the root user on your system. – MadScientist Aug 19 '20 at 12:41

2 Answers2

1

AutoPtr (which was an alias to std::auto_ptr) was removed from Exiv2 in December 2018. Note that std::auto_ptr itself was deprecated from C++ in 2011 and removed altogether in 2017.

Relevant Diff on Github

Your code that depends on AutoPtr is too old. You might be able to update it by replacing AutoPtr with UniquePtr. You will have to find all places where the former auto_ptr was copied (assigned, passed to a function and the like) and insert a call to std::move around the source of the copy. The compiler will complain about a deleted function (copy constructor or copy assignment), so it's easy to fix these places one by one. For example:

 AutoPtr some_variable = ...;
 ...
 some_function(some_variable);

needs to become

 UniquePtr some_variable = ...;
 ...
 some_function(std::move(some_variable));
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • I've got a new error: make g++ -Wall -c -O2 -std=c++11 -I/usr/local/include -L/usr/local/lib -fpic -o metacopy.o metacopy.cpp metacopy.cpp: In member function ‘int Params::copyMetadata(int, char**)’: metacopy.cpp:55:74: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = Exiv2::BasicIo; _Dp = std::default_delete]’ Exiv2::Image::UniquePtr readImg = Exiv2::ImageFactory::open(memIo); – Tomer Barak Aug 19 '20 at 13:26
  • In file included from /usr/include/c++/4.8.2/memory:81:0, from /usr/local/include/exiv2/value.hpp:40, from /usr/local/include/exiv2/metadatum.hpp:37, from /usr/local/include/exiv2/datasets.hpp:32, from /usr/local/include/exiv2/exiv2.hpp:32, from metacopy.cpp:1: /usr/include/c++/4.8.2/bits/unique_ptr.h:273:7: error: declared here unique_ptr(const unique_ptr&) = delete; – Tomer Barak Aug 19 '20 at 13:26
  • /usr/local/include/exiv2/image.hpp:444:33: error: initializing argument 1 of ‘static Exiv2::Image::UniquePtr Exiv2::ImageFactory::open(Exiv2::BasicIo::UniquePtr)’ static Image::UniquePtr open(BasicIo::UniquePtr io); ^ make: *** [metacopy.o] Error 1 – Tomer Barak Aug 19 '20 at 13:26
  • @TomerBarak So you cannot update it in such a simple way, you may have to insert `std::move` where the former auto_ptr was copied. (auto_ptr had weird copy semantics; unique_ptr cannot be copied at all, it must be moved) Will update the answer. – n. m. could be an AI Aug 19 '20 at 13:28
0

This worked:

readImg = Exiv2::ImageFactory::open(std::move(memIo));
Tomer Barak
  • 49
  • 1
  • 4