tsdconseil / opencv-demonstrator

OpenCV demonstrator (GUI)
http://www.tsdconseil.fr/log/opencv/demo/index-en.html
GNU Lesser General Public License v3.0
141 stars 57 forks source link

Build for Apple OS #27

Open juliena82 opened 8 years ago

juliena82 commented 8 years ago

(not prioritary, but it was asked to me by mail by several users)

amckinlay commented 8 years ago

Any idea on what changes need to be make to compile on OS X?

juliena82 commented 8 years ago

I have no precise idea as I don't know OS X. But I suppose that it is similar to Linux, and that GCC is available. So probably the Makefile is already compatible with OS X, but the build instructions (especially how to install opencv) are probably different.

In the end, I think one could start by using Linux build instructions, and and fix step by step when needed.

amckinlay commented 8 years ago

Here is my first attempt at building: https://gist.github.com/amckinlay/82a1068256dc1a24f184.

juliena82 commented 8 years ago

@amckinlay Thanks for your attempt. I hope that you will eventually succeed!

As for the compiling problems, apparently, other people have encoutered a similar problem with pthreads (https://github.com/ratschlab/mmr/issues/1), they suggest to update GCC to at least version 4.7.7. Do you known what version of GCC you are currently using? (gcc --version)

applemuncy commented 8 years ago

I, likewise, have no experience with compiling on a Mac. I'm strictly a Linux person. What I notice is the last error reported that GCC can't find <malloc.h>. I thought at first that might indicate deeper setup problems but reading further about the issue of GCC not finding <malloc.h>, I find information that says malloc is supplied by <stdlib.h> so <malloc.h>. shouldn't be included. Later today I will see what happens if #include <malloc.h> is removed.

amckinlay commented 8 years ago

What is libcutil?

@juliena82 I used Homebrew's GCC, and I no longer get the Pthread compilation errors. Thanks!

@applemuncy You are right. I removed all references to malloc.h.

With those errors resolved, now I get compilation errors in hal.cc. Apparently, Mac doesn't support clock_gettime() (http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x). These abstraction layers over clocks and Pthreads are over my head, so I may not be able to make much more progress. I will try building ocvtext and ocvdemo tonight.

applemuncy commented 8 years ago

@amckinlay , exploring my Ubuntu based system I find that clock_gettime() is from <time.h> that is installed by the libc6 packages. libc6 also installs a copy of <malloc.h> which is why I don't get errors when a program includes <malloc.h>. So I have to conclude your development setup is not complete.

If Homebrew handles dependencies correctly, installing libgtkmm-3.0-1 libgtkmm-3.0-dev should automatically drag in libc6.

And libcutil is @juliena82 personally developed library functions.

amckinlay commented 8 years ago

@applemuncy Is there an alternative C library for OS X? Because the system C library as implemented on OS X does not have the same exact time functions (see StackOverflow link from above) and malloc is not in malloc.h. I'm pretty sure Homebrew does not ship an alternative C library.

amckinlay commented 8 years ago

Almost...

screen shot 2016-02-21 at 11 25 48 pm
juliena82 commented 8 years ago

Congratulations! And does the image processing function work too? Also, if needed, don't hesitate to use alternative if some libararies are not available on Mac. For instance, in the code, you can add

#ifdef __APPLE__
#endif 

to define Apple specific implémentations.

applemuncy commented 8 years ago

OK @amckinlay I follow what you are saying now about clock_gettime(). Would switching to the use of gettimeofday() work for you?

Good to see you are making progress : )

amckinlay commented 8 years ago

The problem lies with both clock_gettime() and CLOCK_MONOTONIC. Both are unsupported on OS X. I compiled with clock_get_time() and mach_timespec_t from mach/clock.h and mach/mach.h instead. But I think I did the conversion incorrectly because ocvdemo.exe hangs on startup. Also, ocvdemo.exe isn't finding a particular .dylib when run from the recommended working directory.

I plan to fix this stuff but not until the end of the week. If you think gettimeofday() is suitable then sure. But I read that it is not a suitable replacement for clock_gettime().

Can I ask why we need hal.h etc. in libcutil? Surely there is a library that provides these features? The code is a little above my pay grade. :) On Feb 22, 2016 12:45 PM, "apple muncy" notifications@github.com wrote:

OK @amckinlay https://github.com/amckinlay I follow what you are saying now about clock_gettime(). Would switching to the use of gettimeofday() work for you?

Good to see you are making progress : )

— Reply to this email directly or view it on GitHub https://github.com/tsdconseil/opencv-demonstrator/issues/27#issuecomment-187287709 .

juliena82 commented 8 years ago

For the demo, probably "gettimeofday()" will do. I used "clock_gettime" because I needed real time behavior, but for other applications, not for the opencv demo. Also, to not break things for the other targets, ideally the "gettimeofday()" alternative should be quoted with "#ifdef __APPLE__" directives. hal.h is here to provide portable Mutex / Signal objects (more specificaly, working also on Windows without pthreads).

applemuncy commented 8 years ago

I suggest gettimeofday() because it would get us by with out the addition of __APPLE__ or __MACH__ . Indeed if there will be other places that will need those include guards, I say fine

juliena82 commented 8 years ago

@applemuncy No, in this case, the addition of __APPLE__ is needed, otherwise it breaks the real time behavior, as would be expected on other projets.

RichLewis007 commented 7 years ago

What's the status of this work?

amckinlay commented 7 years ago

I just gave up. I didn't have the expertise.

RichLewis007 commented 7 years ago

Is anyone else able to help out with this?