Compiling on macOS with cmake and CLion

Get help with compiling or installing the game, and discuss announcements of new official releases.

Moderator: Forum Moderators

Post Reply
nosba
Posts: 7
Joined: January 17th, 2016, 4:49 pm

Compiling on macOS with cmake and CLion

Post by nosba »

Hi all,

I'm trying again to compile and run Wesnoth from sources in CLion with cmake in macOS (I tried last year and I failed: viewtopic.php?f=5&t=44120), while I was compiling I got this errors:

Code: Select all

Undefined symbols for architecture x86_64:
  "_SDL_main", referenced from:
      -[SDLMain applicationDidFinishLaunching:] in libSDLmain.a(SDLMain.o)
  "apple_notifications[code]
::send_notification(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, desktop::notifications::type)", referenced from:
desktop::notifications::send(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, desktop::notifications::type) in notifications.cpp.o
"apple_notifications::available()", referenced from:
desktop::notifications::available() in notifications.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [wesnoth] Error 1
make[2]: *** [src/CMakeFiles/wesnoth.dir/all] Error 2
make[1]: *** [src/CMakeFiles/wesnoth.dir/rule] Error 2
make: *** [wesnoth] Error 2
[/code]

I've solved all the errors adding this line to cmake file:

Code: Select all

if(APPLE)
	set(libwesnoth-game_STAT_SRC
		${libwesnoth-game_STAT_SRC}
		desktop/apple_notification.mm
      macosx/SDLmain.mm
	)
endif(APPLE)
but now when I run the executable "wesnoth" It prints the following output and it blocks it self (waiting something, I suppose):

Code: Select all

objc[51789]: Class SDLApplication is implemented in both /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib (0x1137f0d70) and ~/git/wesnoth/cmake-build-debug/wesnoth (0x1106d6308). One of the two will be used. Which one is undefined.
what should I do to make it run?
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Compiling on macOS with cmake and CLion

Post by Celtic_Minstrel »

I've seen that warning before and it appeared to be harmless; I'm not sure how to fix it, though. Maybe we could just rename the SDLApplication class, I guess? You'd also update the Info.plist file to refer to the renamed class instead of SDLApplication. I don't really expect this to fix your hang, but I guess it's worth a try?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Compiling on macOS with cmake and CLion

Post by mattsc »

Unfortunately I don't know how to help you either, but I can second what Celtic_Minstrel wrote. I get that message every time I start master (compiled using Xcode) and Wesnoth runs just fine after that. So I doubt that that causes your hang.

Edit: One thing to note might be that sometimes, when I first compile a new version, it might take a long time before the Wesnoth window actually appears. As in, a couple minutes or so. After that first time, it usually pops up in a couple seconds.
nosba
Posts: 7
Joined: January 17th, 2016, 4:49 pm

Re: Compiling on macOS with cmake and CLion

Post by nosba »

Hi all,

I found a way to compile and run, thanks to singalen who helped me in the discord's server.

The solution is to change the line 944 in the wesnoth.cpp file (src/wesnoth.cpp) from:

Code: Select all

#ifdef __APPLE__
extern "C" int wesnoth_main(int argc, char** argv);
int wesnoth_main(int argc, char** argv)
#else
int main(int argc, char** argv)
#endif
to

Code: Select all

#ifdef __IPHONEOS__
extern "C" int wesnoth_main(int argc, char** argv);
int wesnoth_main(int argc, char** argv)
#else
int main(int argc, char** argv)
#endif
doing that changes it's possible to restore the original CMakeLists.txt.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Compiling on macOS with cmake and CLion

Post by Celtic_Minstrel »

I wonder if everything works correctly when you do that, though. There should be some custom menuitems in the application menu to launch the website and show the changelog, for example. And do key-equivalents for the application menu work? For example, Cmd+H for hide. Basically anything in this file. Also, if you don't change the CMake file to include apple_notifications.mm, I assume you won't be able to enable the native notifications that pop up to inform you that it's your turn.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply