fltk programm compile with cmake on mac OSX

105 views
Skip to first unread message

Julien Ithurbide

unread,
May 10, 2015, 10:27:46 AM5/10/15
to fltkg...@googlegroups.com
Hello,

I compile a soft on linux with this cmake file :

cmake_minimum_required(VERSION 2.8.4)
project
(LCD)
set(CMAKE_OSX_ARCHITECTURES "x86_64" )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS " -stdlib=libstdc++")
SET
(FLTK_DIR /path/to/source/build)

find_package
(FLTK REQUIRED NO_MODULE)
include
(${FLTK_USE_FILE})

set(SOURCE_FILES lcd.cpp)
add_executable
(LCD ${SOURCE_FILES})
TARGET_LINK_LIBRARIES
(LCD fltk)

On liunx, it's works like a charm.

But, Now, I want to compile on mac osx. I have compile and install fltk with this command :


cd /path/to/source/
mkdir build
cd build
cmake ..
make
sudo make install

In fact, in linux I dont need to add this line on my cmake file :

SET(FLTK_DIR /path/to/source/build)

But on mac osx, I need to add it. I can compile my soft but in the linking step my compiler tell me this :


ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [LCD] Error 1
make[1]: *** [CMakeFiles/LCD.dir/all] Error 2
make: *** [all] Error 2



Can someone help me to compile my application ?

Julien













Michael Surette

unread,
May 10, 2015, 2:04:54 PM5/10/15
to fltkg...@googlegroups.com
On Sun, May 10, 2015 at 6:26 AM, Julien Ithurbide wrote:
> Hello,
>
> I compile a soft on linux with this cmake file :
>
> cmake_minimum_required(VERSION 2.8.4)
> project(LCD)
> set(CMAKE_OSX_ARCHITECTURES "x86_64" )
>
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

> set( " -stdlib=libstdc++")

You should change this to be like the previous line. ie
---
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
---
otherwise you lose previous settings.

or alternatively you can use
---
list(APPEND CMAKE_CXX_FLAGS -std=c++11 -stdlib=libstdc++)
---
either with a separate line for each flag or combined as shown.

> SET(FLTK_DIR /path/to/source/build)
>
> find_package(FLTK REQUIRED NO_MODULE)
> include(${FLTK_USE_FILE})
>
> set(SOURCE_FILES lcd.cpp)
> add_executable(LCD ${SOURCE_FILES})
> TARGET_LINK_LIBRARIES(LCD fltk)
>
> On liunx, it's works like a charm.
>
> But, Now, I want to compile on mac osx. I have compile and install fltk with
> this command :
>
>
> cd /path/to/source/
> mkdir build
> cd build
> cmake ..
> make
> sudo make install
>
> In fact, in linux I dont need to add this line on my cmake file :
> SET(FLTK_DIR /path/to/source/build)

When you install FLTK to a standard location, you don't have to set
FLTK_DIR, find_package looks in all the standard locations
automatically. I'm surprised that this isn't the case with OSX.

> But on mac osx, I need to add it. I can compile my soft but in the linking
> step my compiler tell me this :
>
>
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> make[2]: *** [LCD] Error 1
> make[1]: *** [CMakeFiles/LCD.dir/all] Error 2
> make: *** [all] Error 2

I'm not familiar with the OSX build system, but I know that FLTK with
CMake has been tested on it. Here are a couple of things you could
try.

"make VERBOSE=1" should give more details on the build process.

The SET(FLTK_DIR ...) should point to the location of the
FLTKConfig.cmake FLTK-Targets.cmake and UseFLTK.cmake files. These
are all plaintext files that should have the proper paths for your
includes and libraries, as well as your dependencies and flags.
Verify that these are all ok.

If this doesn't help then we'll have to wait for someone with some OSX
experience.

Let us know what you find.
--
Mike

Albrecht Schlosser

unread,
May 11, 2015, 7:17:21 AM5/11/15
to fltkg...@googlegroups.com
On 10.05.2015 20:04 Michael Surette wrote:
> On Sun, May 10, 2015 at 6:26 AM, Julien Ithurbide wrote:
>> Hello,
>>
>> I compile a soft on linux with this cmake file :
>>
>> cmake_minimum_required(VERSION 2.8.4)
>> project(LCD)
>> set(CMAKE_OSX_ARCHITECTURES "x86_64" )
>>
>> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
>
>> set( " -stdlib=libstdc++")
>
> You should change this to be like the previous line. ie
> ---
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
> ---
> otherwise you lose previous settings.

Agreed.

> or alternatively you can use
> ---
> list(APPEND CMAKE_CXX_FLAGS -std=c++11 -stdlib=libstdc++)
> ---
> either with a separate line for each flag or combined as shown.

Not recommended. This would add semicolons (";") between arguments,
because the resulting variable would be treated as a list internally.

You can "fix" it though (if you like to do this) with an additional
statement:

string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

Otherwise the compiler would complain when it encounters the options
separated by ";".

Well, just tested: it's not only the compiler who complains, because the
";" terminates the command line prematurely. I get:

c++: fatal error: no input files
compilation terminated.
/bin/sh: 1: -Wall: not found
/bin/sh: 1: -Wno-unused-parameter: not found

The first two lines are compiler messages, whereas the other two lines
result from the ";" and the other options I used for testing.

> If this doesn't help then we'll have to wait for someone with some OSX
> experience.

Unfortunately I can't help with OSX either.
Reply all
Reply to author
Forward
0 new messages