Libui: Compile error on mac

Created on 18 Mar 2018  ·  19Comments  ·  Source: andlabs/libui

The examples don't compile on macOS, because libc++ is used by default instead of libstdc++ only with a deployment target of 10.9 or newer. (So --stdlib=libstdc++ need to be passed).

libui/examples/cpp-multithread/main.cpp:2:10: fatal error: 'thread' file not found
#include <thread>
         ^~~~~~~~
1 error generated.

(after the utflib-and-attrstr merge)

Most helpful comment

Yes, I have not committed those fixes yet. I'll do that tonight.

All 19 comments

I don't understand what the merge did to change that build rule. If cmake is being dumb again and silently changed a default recently, that just gives me more reason to jettison cmake. If you can instead pin an exact commit that broke this, that would be nice, because I can reproduce it too, but Google only gives me results for 10.8 itself. I'm on 10.12.

I will investigate.

More compile errors:

$ make tester
[ 71%] Built target libui
[ 73%] Building C object test/CMakeFiles/tester.dir/page8.c.o
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:6:2: error: use of undeclared identifier 'uiDrawFontFamilies'
        uiDrawFontFamilies *ff;
        ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:6:22: error: use of undeclared identifier 'ff'
        uiDrawFontFamilies *ff;
                            ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:11:2: error: use of undeclared identifier 'ff'
        ff = uiDrawListFontFamilies();
        ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:11:7: warning: implicit declaration of function 'uiDrawListFontFamilies' is invalid
      in C99 [-Wimplicit-function-declaration]
        ff = uiDrawListFontFamilies();
             ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:12:6: warning: implicit declaration of function 'uiDrawFontFamiliesNumFamilies' is
      invalid in C99 [-Wimplicit-function-declaration]
        n = uiDrawFontFamiliesNumFamilies(ff);
            ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:12:36: error: use of undeclared identifier 'ff'
        n = uiDrawFontFamiliesNumFamilies(ff);
                                          ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:14:10: warning: implicit declaration of function 'uiDrawFontFamiliesFamily' is
      invalid in C99 [-Wimplicit-function-declaration]
                this = uiDrawFontFamiliesFamily(ff, i);
                       ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:14:35: error: use of undeclared identifier 'ff'
                this = uiDrawFontFamiliesFamily(ff, i);
                                                ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:19:2: warning: implicit declaration of function 'uiDrawFreeFontFamilies' is invalid
      in C99 [-Wimplicit-function-declaration]
        uiDrawFreeFontFamilies(ff);
        ^
/Users/niklas/Desktop/DEV-TEST/libui/libui/test/page8.c:19:25: error: use of undeclared identifier 'ff'
        uiDrawFreeFontFamilies(ff);
                               ^
4 warnings and 6 errors generated.
make[3]: *** [test/CMakeFiles/tester.dir/build.make:375: test/CMakeFiles/tester.dir/page8.c.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:159: test/CMakeFiles/tester.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:166: test/CMakeFiles/tester.dir/rule] Error 2
make: *** [Makefile:131: tester] Error 2

Commit that caused this: https://github.com/andlabs/libui/commit/aa455be1aed1063f3fec9433757f0a3323b66b3c (I have always wanted to try out git bisect, worked really well)

I have 10.12 as well.

The old CMAKE_OSX_DEPLOYMENT_TARGET declaration without CACHE ... somehow didn't do anything at all.

Adding this line fixes it:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fbcb3358..0b4e0d67 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,6 +49,7 @@ if(APPLE)
        # the / is required by some older versions of OS X
        set(CMAKE_INSTALL_RPATH "@executable_path/")
        set(CMAKE_MACOSX_RPATH TRUE)
+       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --stdlib=libc++")
 elseif(WIN32)
        set(_OSNAME windows)

I have no idea why it works with CACHE STRING "" FORCE, for me it worked succesfully without that in the past.

And:

$ make examples
[ 88%] Built target libui
[ 91%] Built target controlgallery
[ 94%] Built target cpp-multithread
[ 97%] Built target histogram
[100%] Built target drawtext
make[3]: *** No rule to make target '../examples/opentype', needed by 'examples/CMakeFiles/examples'.  Stop.
make[2]: *** [CMakeFiles/Makefile2:248: examples/CMakeFiles/examples.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:255: examples/CMakeFiles/examples.dir/rule] Error 2
make: *** [Makefile:157: examples] Error 2

Yes, the tester has to be updated and it seems like I missed a spot in the examples CMakeLists.txt.

CACHE STRING "" FORCE is cmake voodoo magic that you need on some of the variables that begin with CMAKE_, otherwise cmake will just silently not accept your changes to that variable, because cmake.

So what is this about libc++ and the deployment target anyway? I still don't fully understand what's causing this error, even after reading what you said so far.

I think this issue is related to #269?

The default c++ standard library on OS X was libstdc++. It wasn't compatible with C++11, so for that libc++ had to be used.
Starting with OSX 10.9, the default library was changed from libstdc++ to libc++. Before that (e.g. with a deployment target of 10.8), you have/had to specifically pass -stdlib=libc++ to be able to use C++11.

The disadvantage is that libstdc++ 4.2 predates the c++11 standard; it does not support most of the c++11 features. So, your code that uses std::forward, etc will not compile with this library, even if you turn on c++11 support in clang – this switch only controls what language the compiler will accept.

(https://cplusplusmusings.wordpress.com/2012/07/05/clang-and-standard-libraries-on-mac-os-x/)


You commented in that pull request, that that example is the only place with C++ on mac. So the solution there would be cleaner than my global one.

I was able to compile my fork on macOS.
I'm not exactly sure what is the related one, I had made so many changes to the cmake file...

Also the examples and the tester?

Ops no, my apologies, examples and tests fails...

Interesting, the build for #157 failed because of #302 (comment) but travis is reporting "successful".

I saw, that's really strange. Maybe it's because main cmake project is passing and the offending ones are sub-projects?

(This is isn't related to this issue, I commented on your PR)

image

Fixed example by adding

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --stdlib=libc++ --std=c++11")

to relative CMakeLists file

Anyway, there are other compilation errors. I pushed anyway the changes so they are available on travis and appveyor if you want to review them.

tests:

❯ make tester                                                                                                                      ⏰ 0,462s 22:42:09
[ 71%] Built target libui
[ 73%] Building C object test/CMakeFiles/tester.dir/page8.c.o
/Users/parroit/repos/libui/test/page8.c:6:2: error: use of undeclared identifier 'uiDrawFontFamilies'
        uiDrawFontFamilies *ff;
        ^
/Users/parroit/repos/libui/test/page8.c:6:22: error: use of undeclared identifier 'ff'
        uiDrawFontFamilies *ff;
                            ^
/Users/parroit/repos/libui/test/page8.c:11:2: error: use of undeclared identifier 'ff'
        ff = uiDrawListFontFamilies();
        ^
/Users/parroit/repos/libui/test/page8.c:11:7: warning: implicit declaration of function 'uiDrawListFontFamilies' is invalid in C99
      [-Wimplicit-function-declaration]
        ff = uiDrawListFontFamilies();
             ^
/Users/parroit/repos/libui/test/page8.c:12:6: warning: implicit declaration of function 'uiDrawFontFamiliesNumFamilies' is invalid in C99
      [-Wimplicit-function-declaration]
        n = uiDrawFontFamiliesNumFamilies(ff);
            ^
/Users/parroit/repos/libui/test/page8.c:12:36: error: use of undeclared identifier 'ff'
        n = uiDrawFontFamiliesNumFamilies(ff);
                                          ^
/Users/parroit/repos/libui/test/page8.c:14:10: warning: implicit declaration of function 'uiDrawFontFamiliesFamily' is invalid in C99
      [-Wimplicit-function-declaration]
                this = uiDrawFontFamiliesFamily(ff, i);
                       ^
/Users/parroit/repos/libui/test/page8.c:14:35: error: use of undeclared identifier 'ff'
                this = uiDrawFontFamiliesFamily(ff, i);
                                                ^
/Users/parroit/repos/libui/test/page8.c:19:2: warning: implicit declaration of function 'uiDrawFreeFontFamilies' is invalid in C99
      [-Wimplicit-function-declaration]
        uiDrawFreeFontFamilies(ff);
        ^
/Users/parroit/repos/libui/test/page8.c:19:25: error: use of undeclared identifier 'ff'
        uiDrawFreeFontFamilies(ff);
                               ^
4 warnings and 6 errors generated.
make[3]: *** [test/CMakeFiles/tester.dir/page8.c.o] Error 1
make[2]: *** [test/CMakeFiles/tester.dir/all] Error 2
make[1]: *** [test/CMakeFiles/tester.dir/rule] Error 2
make: *** [tester] Error 2

🦈  ~/r/l/build  (master 🤪 )
❯                                                                                                                                  ⏰ 0,379s 22:42:15

and examples:

❯ make examples                                                                                                                    ⏰ 0,379s 22:42:15
[ 88%] Built target libui
[ 91%] Built target controlgallery
[ 94%] Built target cpp-multithread
[ 97%] Built target histogram
[100%] Built target drawtext
make[3]: *** No rule to make target `../examples/opentype', needed by `examples/CMakeFiles/examples'.  Stop.
make[2]: *** [examples/CMakeFiles/examples.dir/all] Error 2
make[1]: *** [examples/CMakeFiles/examples.dir/rule] Error 2
make: *** [examples] Error 2

🦈  ~/r/l/build  (master 🤪 )
❯                                                                                                                                  ⏰ 0,512s 22:43:30




























First error reported in https://github.com/andlabs/libui/issues/302#issuecomment-374043586
Second error in https://github.com/andlabs/libui/issues/302#issuecomment-374054282

Response:

Yes, the tester has to be updated and it seems like I missed a spot in the examples CMakeLists.txt.

Oh ok, I missed that, thank you

I fixed example by removing include for "opentype" example. @andlabs do you forget to commit it?
I fixed tester by commenting page8, page9 and page10. They seem to be using removed UiArea APIs

Yes, I have not committed those fixes yet. I'll do that tonight.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chptx picture chptx  ·  6Comments

amar-laksh picture amar-laksh  ·  4Comments

parro-it picture parro-it  ·  3Comments

krakjoe picture krakjoe  ·  9Comments

justasmalinauskas picture justasmalinauskas  ·  5Comments