Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using with clang on Windows  (Read 12917 times)

0 Members and 2 Guests are viewing this topic.

_LB

  • Newbie
  • *
  • Posts: 7
    • View Profile
Using with clang on Windows
« on: May 28, 2013, 10:45:43 pm »
Hi, I've been using clang++ on Windows with many projects for quite some time for its C++11 support, but with SFML I'm getting some issues. I cannot link to any of the precompiled binaries, so I have to make my own. I can generate and build with MinGW Makefiles, and can link to them, but the program crashes when using any SFML call (e.g. ctor for sf::RenderWindow). I'm trying to actually build with clang++ so I can use C++11, not MinGW (I'm using the official version of clang for MinGW on Windows).

I have so far this command line to run cmake to generate makefiles for clang:
cmake -G "MinGW Makefiles" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="-std=c++11" .

Unfortunately I get this error:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPack
ageHandleStandardArgs.cmake:97 (message):
  Could NOT find Freetype (missing: FREETYPE_LIBRARY) (found version "2.4.4")
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStan
dardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindFreetype.cmake:10
7 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  src/SFML/Graphics/CMakeLists.txt:102 (find_package)

The only thing I could find was this thread:
http://en.sfml-dev.org/forums/index.php?topic=8787.0
But it doesn't seem to apply to me since I am on Windows.

Does anyone know why it is complaining about not being able to find freetype even though it can if I just just cmake for MinGW? I'm on a Windows 7 64-bit machine but I'm running clang++ and MinGW as 32-bit.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using with clang on Windows
« Reply #1 on: May 28, 2013, 11:27:10 pm »
SFML has precompiled FreeType (and other dependencies) for VC++ and MinGW, but not for Clang. I don't know if static C libraries compiled with gcc are compatible with clang; if so, then I can easily change the CMake files to take it in account.
Laurent Gomila - SFML developer

_LB

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Using with clang on Windows
« Reply #2 on: May 31, 2013, 03:14:32 am »
I actually have no idea how to do that. Where would I substitute the gcc libraries to test?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using with clang on Windows
« Reply #3 on: May 31, 2013, 08:03:17 am »
You can manually set the CMake variable (FREETYPE_LIBRARY) to the path of the library in extlibs/libs/mingw/. Same for other errors that will happen next.
Laurent Gomila - SFML developer

_LB

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Using with clang on Windows
« Reply #4 on: June 02, 2013, 06:43:17 pm »
Thanks! My build command now looks like this:

cmake -G "MinGW Makefiles" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="-std=c++11" -DFREETYPE_LIBRARY=./extlibs/libs/mingw/ -DGLEW_LIBRARY=./extlibs/libs/mingw/ -DJPEG_LIBRARY=./extlibs/libs/mingw/ -DOPENAL_LIBRARY=./extlibs/libs/mingw/ -DSNDFILE_LIBRARY=./extlibs/libs/mingw/ .

I'm using "mingw32-make" to build the makefiles. clang generates a lot of warnings about dllexport/import attributes, and then gives an error:

Linking CXX shared library ..\..\..\lib\sfml-system-2.dll
Cannot export __ZN2sf12microsecondsEx: symbol not found
Cannot export __ZN2sf12millisecondsEi: symbol not found
Cannot export __ZN2sf3errEv: symbol not found
Cannot export __ZN2sf5sleepENS_4TimeE: symbol not found
Cannot export __ZN2sf7secondsEf: symbol not found
Cannot export __ZN2sfdVERNS_4TimeEf: symbol not found
Cannot export __ZN2sfdVERNS_4TimeEx: symbol not found
Cannot export __ZN2sfdvENS_4TimeEf: symbol not found
Cannot export __ZN2sfdvENS_4TimeEx: symbol not found
Cannot export __ZN2sfeqENS_4TimeES0_: symbol not found
Cannot export __ZN2sfeqERKNS_6StringES2_: symbol not found
Cannot export __ZN2sfgeENS_4TimeES0_: symbol not found
Cannot export __ZN2sfgeERKNS_6StringES2_: symbol not found
Cannot export __ZN2sfgtENS_4TimeES0_: symbol not found
Cannot export __ZN2sfgtERKNS_6StringES2_: symbol not found
Cannot export __ZN2sfleENS_4TimeES0_: symbol not found
Cannot export __ZN2sfleERKNS_6StringES2_: symbol not found
Cannot export __ZN2sfltENS_4TimeES0_: symbol not found
Cannot export __ZN2sfltERKNS_6StringES2_: symbol not found
Cannot export __ZN2sfmIERNS_4TimeES0_: symbol not found
Cannot export __ZN2sfmLERNS_4TimeEf: symbol not found
Cannot export __ZN2sfmLERNS_4TimeEx: symbol not found
Cannot export __ZN2sfmiENS_4TimeES0_: symbol not found
Cannot export __ZN2sfmlENS_4TimeEf: symbol not found
Cannot export __ZN2sfmlENS_4TimeEx: symbol not found
Cannot export __ZN2sfmlEfNS_4TimeE: symbol not found
Cannot export __ZN2sfmlExNS_4TimeE: symbol not found
Cannot export __ZN2sfneENS_4TimeES0_: symbol not found
Cannot export __ZN2sfneERKNS_6StringES2_: symbol not found
Cannot export __ZN2sfngENS_4TimeE: symbol not found
Cannot export __ZN2sfpLERNS_4TimeES0_: symbol not found
Cannot export __ZN2sfplENS_4TimeES0_: symbol not found
Cannot export __ZN2sfplERKNS_6StringES2_: symbol not found
collect2.exe: error: ld returned 1 exit status
clang++: error: linker (via gcc) command failed with exit code 1 (use -v to see
invocation)
mingw32-make[2]: *** [lib/sfml-system-2.dll] Error 1
mingw32-make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2
mingw32-make: *** [all] Error 2

I'm not sure what to do from this point, unfortunately - I'm not very familiar with creating libraries or DLLs with clang.

_LB

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Using with clang on Windows
« Reply #5 on: June 03, 2013, 08:01:17 pm »
The warnings I get all look like this:

In file included from C:\Users\Nicholas\Desktop\GitHub\TaylorPolynomials\lib\SFM
L\src\SFML\System\Win32\ThreadLocalImpl.cpp:28:
In file included from C:\Users\Nicholas\Desktop\GitHub\TaylorPolynomials\lib\SFM
L\src\SFML/System/Win32/ThreadLocalImpl.hpp:31:
C:\Users\Nicholas\Desktop\GitHub\TaylorPolynomials\lib\SFML\include\SFML/System/
NonCopyable.hpp:41:7: warning:
      'dllexport' attribute only applies to variables and functions
      [-Wignored-attributes]
class SFML_SYSTEM_API NonCopyable
      ^
C:\Users\Nicholas\Desktop\GitHub\TaylorPolynomials\lib\SFML\include\SFML/System/
Export.hpp:39:29: note:
      expanded from macro 'SFML_SYSTEM_API'
    #define SFML_SYSTEM_API SFML_API_EXPORT
                            ^
C:\Users\Nicholas\Desktop\GitHub\TaylorPolynomials\lib\SFML\include\SFML/Config.
hpp:88:44: note:
      expanded from macro 'SFML_API_EXPORT'
        #define SFML_API_EXPORT __declspec(dllexport)
                                           ^
<built-in>:155:38: note: expanded from macro '__declspec'
#define __declspec(a) __attribute__((a))
                                     ^
This makes me think that even though the classes are configured to export, it's being ignored because it has to be applied to every member of the class instead.

I changed my command line to this:

cmake -G "MinGW Makefiles" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="-std=c++11" -DFREETYPE_LIBRARY=./extlibs/libs/mingw/ -DGLEW_LIBRARY=./extlibs/libs/mingw/ -DJPEG_LIBRARY=./extlibs/libs/mingw/ -DOPENAL_LIBRARY=./extlibs/libs/mingw/ -DSNDFILE_LIBRARY=./extlibs/libs/mingw/ -DBUILD_SHARED_LIBS=0 .

(it now includes -DBUILD_SHARED_LIBS=0) and I no longer get warnings or errors when compiling with mingw32-make :D

Now I just have to check if I can link with my project - hopefully statically linking will work.

_LB

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Using with clang on Windows
« Reply #6 on: June 03, 2013, 11:15:57 pm »
Nope, it can't link. I'm having to compile all five dependencies by hand and it's a nightmare. Do you have any suggestions or advice?

izackp

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Using with clang on Windows
« Reply #7 on: August 25, 2014, 12:54:20 pm »
Your error was happening because clang didn't support dll export on structs and class.

The latest snapshot version of clang has this problem solved:
http://llvm.org/builds/

or you can build llvm yourself using any commit past July.


I am still getting linking errors with the .dll though. I'll probably post here when I figure out how to fix that.
Meh Blog: iDevStudio

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Using with clang on Windows
« Reply #8 on: August 25, 2014, 02:09:19 pm »
You just bumped a 1+ year old thread... I really doubt the OP is going to return and if you have a similar problem you should probably start a new thread.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

izackp

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Using with clang on Windows
« Reply #9 on: August 25, 2014, 05:44:16 pm »
This is one of the top ranked threads when searching in google for "sfml clang windows". 

I added the solution here, so everyone else, who searches for that phrase in google, can find this information.
Meh Blog: iDevStudio

 

anything