• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
hatfarm

CMake linking issue with SFML/GLEW in Linux

11 posts in this topic

Okay, I decided I'd make a new post since the last one kinda got away from the original intent.  So, I'm trying to build my application and I've got all my code compiling, but it's not linking and I'm not sure why.  I kinda reworked the setup, I've got my engine that I've worked on and it compiles and links fine.  My game code is compiling, but it will not find the link to the GLEW and SFML libraries.  I cannot figure out why.  It works fine with my setup in Windows, but Linux apparently hates it.  Here's my top level CMakeLists.txt:

 

cmake_minimum_required(VERSION 2.6.4)
project(Balls)

ADD_SUBDIRECTORY(bate)

include_directories(
	${CMAKE_CURRENT_SOURCE_DIR}/include
	${BATE_INCLUDES}
)

set(EXEC_NAME "Balls to the Walls")

set(Balls_SRCS	
	src/application.cpp	
	src/ball.cpp
	src/ballswindow.cpp
	src/brick.cpp
	src/component.cpp
	src/entity.cpp	
	src/main.cpp
	src/menustate.cpp
	src/position.cpp
	src/system.cpp
	src/velocity.cpp
	
)

set(Balls_INC
	include/application.h
	include/ball.h
	include/ballswindow.h
	include/brick.h
	include/component.h
	include/entity.h
	include/menustate.h
	include/position.h
	include/system.h
	include/velocity.h
)

ADD_DEFINITIONS( -DSFML_STATIC )
	
add_executable(${EXEC_NAME} ${Balls_SRCS} ${Balls_INC})

SET_TARGET_PROPERTIES(${EXEC_NAME}
	PROPERTIES
	COMPILE_DEFINITIONS
	"GLEW_STATIC="
)

TARGET_LINK_LIBRARIES(${EXEC_NAME} BatE )

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    # Linux specific code
    SET_TARGET_PROPERTIES(${EXEC_NAME}
	PROPERTIES
	COMPILE_DEFINITIONS
	"IS_LINUX="
    )
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

# Install target
install(TARGETS ${EXEC_NAME} DESTINATION bin)

BatE is my engine (Battle Engine).  I've tried linking SFML here, but that didn't change anything.  Any advice?

0

Share this post


Link to post
Share on other sites

Gah!  I figured out why the problem is happening, a bit.  Part of the reason is that the environment variables are not getting read properly by CMake.  I've got SFML_ROOT defined in the /etc/environment file, and then I also can print out $SFML_ROOT in the terminal and it works, but CMake does not recognize them (I put a MESSAGE statement in there).  So, that's the problem, but I'm not sure how to fix it.  I even wrote a script that created the environment variable, then exported it and prints it out, it prints them all out, but it is not finding it inside of CMake...

 

Anyone have any ideas?

0

Share this post


Link to post
Share on other sites

Well, I got around the issue a bit.  I created a bash script that exports the variables and then calls cmake-gui.  It works, it's lame, but it works.  However, then it has trouble finding any of the libraries that SFML links against.  This is incredibly frustrating.

0

Share this post


Link to post
Share on other sites

Sorry for the delay in replying.  Been running around lately..

 

In order to work with environment variables in CMake, you simply prepend "ENV" to the variable.  So, in order to tell Cmake to read your environment variable SFML_ROOT, you do the following:

 

SET( SFML_ROOT ENV{SFML_ROOT} )

 

Now SFML_ROOT has been imported from the environment variable and you can use it as a normal CMake variable.  That should get around the script file issue if I understood your needs correctly.

0

Share this post


Link to post
Share on other sites

That's actually how I've been working with it.  I'm still not sure why that issue is happening, but now I'm having issues with the libraries linked by SFML.  I'm working on that, but I'm having an issue with CMake saying: "Cannot specify link libraries for target

"/usr/lib/i386-linux-gnu/libGLU.so" which is not built by this project."

 

Any ideas?  It appears I've got GLU installed, that doesn't appear to be the issue.  Why is it so much more brutal in Linux?

0

Share this post


Link to post
Share on other sites

That's actually how I've been working with it.  I'm still not sure why that issue is happening, but now I'm having issues with the libraries linked by SFML.  I'm working on that, but I'm having an issue with CMake saying: "Cannot specify link libraries for target

"/usr/lib/i386-linux-gnu/libGLU.so" which is not built by this project."

 

Any ideas?  It appears I've got GLU installed, that doesn't appear to be the issue.  Why is it so much more brutal in Linux?

 

This is the annoying thing in this thread (and the old one), I usually find Linux to be very simple to fix compared to all the f'd up Windows nonsense.  I don't mean to say the thread is annoying or anything, just that the worst case for me is always Windows and you always seem to run into Linux issues. :)

 

To be honest, it really looks like a problem in the CMake code but without further details I simply can not give you a lot of feedback.  I "THINK" that the error is specifying that you are trying to set target dependencies on something which is not part of your build, i.e. libGLU.  Unfortunately I don't see anything wrong with your posted CMake lists file but it doesn't have anything to do with libGLU so, that doesn't mean much.

 

Given the information I'd step back and remove that bash script and try to fix that bit first.  There is a problem somewhere and by using a script you are not fixing a possible source of the problems.  You should not need a script at all, that's the reason for CMake. :)

0

Share this post


Link to post
Share on other sites

So, I've fixed a couple of issues.  This OpenGL issue has gone away, I was telling it to link against my executable and not the library, which was a problem, because the executable wasn't defined in the library's .txt file.  The script issue has just gone away, it wasn't solved by just restarting, because I didn't change anything between restarts in order to get it to work, but it's working without the script, so I'm not complaining about not making any headway.  I'm having a problem with it not finding X11 in Linux.  I have X11, because it compiled SFML fine, but as far as my makefile is concerned, it's not being linked properly.  I get this error when I try to make in Linux:
 

/usr/bin/ld: /home/hatfarm/SFML-2.1//lib/libsfml-window-s.a(WindowImplX11.cpp.o): undefined reference to symbol 'XGetWindowAttributes'
/usr/bin/ld: note: 'XGetWindowAttributes' is defined in DSO /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/libX11.so so try adding it to the linker command line
/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/libX11.so: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

Here's the code I have in my CMakeLists.txt file that should ensure that X11 is linked properly:
 

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    find_package(X11 REQUIRED)
    set(LIB_INCLUDES
        ${LIB_INCLUDES}
        ${X11_INCLUDE_DIR})
    set(LIB_LINKS
    	${LIB_LINKS} ${X11_LIBRARIES} )
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

That's in both my library and executable's CMakeFiles.txt...

I know that LIB_INCLUDES and LIB_LINKS are correctly used because it doesn't complain about OpenGL.  Any ideas?

0

Share this post


Link to post
Share on other sites

That's a pretty confusing one.  It looks as if the compiler "is" attempting to link the library, i.e. the "Invalid operation" message but the symbols are not getting read in correctly.  It makes me wonder if somehow you have mixed 32bit/64bit code somehow.  I setup a quick little experiment myself and had no problem getting SFML and X11 linked into a little test app, so that didn't give me any leads.  I'll keep thinking about it but I don't see anything particularly wrong.  The one thing I could suggest is to simply insert a "MESSAGE( "LIB_LINKS: ${LIB_LINKS}" )" after your block of code and make sure it looks correct, doesn't have any extra spaces, incorrect backslashes etc.  That's always my starting point, just start spitting out as much as possible till one looks incorrect. :)

0

Share this post


Link to post
Share on other sites

Well, the weirdest thing is, I can make the examples for SFML fine.  There's specifically an X11 example, and I checked that CMake file in order to get what I should put here.  When I make that, it works fine.  I really can't figure out what the deal is here though...  I actually have the exact message print that you put, and nothing looks funny, except the include directories don't appear to have ';' after them, but that doesn't appear to be the issue.  This is incredibly frustrating, because I just want to code.

0

Share this post


Link to post
Share on other sites
Cross platform stuff is a pain in the bloody ass unfortunately. Cmake makes it considerably easier but is still not a silver bullet. If you can't get it figured out soon, you could give me source access and I'll fix things up for you. I'll even sign an NDA or whatever if needed. NOTE: This is a one time offer, just figure since you've used my new forum the most, it's worth it.. smile.png
0

Share this post


Link to post
Share on other sites

I REALLY REALLY appreciate the offer, it's in such an infant stage right now that I'm not that worried about an NDA or anything like that.  However, I kind of got it working last night.  I cleaned up the CMakeLists.txt and did things the way SFML does in their examples.  That got me past the immediate error, but moved it down the line to the pthread library.  SFML doesn't do a find_package(pthread) nor could I, so I decided that since Linux is easier to get these libraries with, I'd just use the dynamic libraries for Linux.  So, I have it use the static libraries for Windows and then in Linux it uses the static libraries.  I'm getting wildly different behavior in Linux (one of my assertions, which doesn't get thrown in Windows gets thrown immediately in Linux).  I'm going to have to work through that, but I'm happy to be doing that rather than messing with CMake.  

 

Thank you so much for your help, I'm sure once I go to build on Mac, I'll have plenty more questions, but I'm doing okay now.

0

Share this post


Link to post
Share on other sites

I guess there is one more issue I'm having.  make clean is just not working.  When I type that in, it says:

 

"cmake_clean.cmake:21 (INCLUDE):

  include called with wrong number of arguments.  Include only takes one
  file."
 
This is in Linux, with MSVC2010, I have no issues.  Any ideas?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0