Ask Your Question
0

cv::Tracker linker error in Xcode?

asked 2017-08-09 15:11:52 -0600

Melkarid gravatar image

Every time I try to initialize a cv::Tracker I receive a "Apple Mach-O Linker (Id) Error". I've searched extensively for solutions, having

  • Included #include <opencv2 tracking="" tracking.hpp="">
  • Updated all the search paths in build settings
  • Updated the frameworks in build paths
  • Cleaned the product, restarted Xcode
  • Rebuilt the opencv2 framework with contrib (so tracking is definitely there)

Nothing works. I keep getting this error and everything else runs fine if I comment out

"Ptr<tracker> tracker = Tracker::create("KCF");"

Any help is appreciated!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-11 12:20:19 -0600

updated 2017-08-11 12:24:47 -0600

A couple problems.

Coding Related

  1. I stand to be corrected but in C++, #include <opencv2 tracking="" tracking.hpp=""> is an invalid statement. In order to include the tracking header, you need this #include <opencv2/tracking.hpp> instead. Read more on header files.

  2. Class names are case-sensitive. Ptr<tracker> tracker != Ptr<Tracker> tracker. OpenCV's class is called Tracker and not tracker.

To add onto this, depending on the OpenCV version; from 3.1.0 onwards, Ptr<Tracker> tracker = Tracker::create("KCF"); is actually an invalid statement as well. This was changed to Ptr<Tracker> tracker = TrackerKCF::create(); Here's more info how this API was changed from 3.1.0.

Linker Related

Linker errors occur when the compiler just fails to find all of the appropriate ingredients to create an executable that can be loaded onto your OS. Typo in function/method names, missing main() etc are some of the culprits. I would recommend you read more about these errors.

For your case, since tracking is an opencv_contrib module and according to their README:

to run, linker flags to contrib modules will need to be added to use them in your code/IDE. For example to use the aruco module, "-lopencv_aruco" flag will be added.

To fix this, navigate to your Project->Build Settings-> (Search for Other Linker).

Under Other Linker Flags, add -lopencv_tracking then build your project.

Always remember to add flags for each contrib module used.

Happy coding, cheers mate ;)

edit flag offensive delete link more

Comments

Use pkg-config --cflags --libs opencv to generate all the linker flags.

babahooja gravatar imagebabahooja ( 2018-10-28 04:56:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-09 15:11:52 -0600

Seen: 777 times

Last updated: Aug 11 '17