jeremyletang / rust-sfml

SFML bindings for Rust
Other
638 stars 88 forks source link

Cargo run example fails to build (Mac) #249

Closed DennisPing closed 3 years ago

DennisPing commented 3 years ago

Cargo run --example pong fails to build (Mac)

Description

I have compiled and ran SFML 2.5.1 programs in C++ before. I followed the Wiki, but I get a lot of errors during the end of the build (step 70/73). I've tried both the Homebrew method and the Git clone method, but they both crashed on the same step.

I tried hardcoding my EXPORT path just in case:

export LIBRARY_PATH=/usr/local/Cellar/sfml/2.5.1_1/lib:/usr/local/Cellar/csfml/2.5.1/lib
export DYLD_LIBRARY_PATH=/usr/local/Cellar/sfml/2.5.1_1/lib:/usr/local/Cellar/csfml/2.5.1/lib

It still still crashes on the same step.

Trying another build system

I have another build system called Ninja which I have used before on C++. Trying to build with Ninja also crashes on the same step 😭

Your environment

Error Output Samples

  --- stdout
  cargo:rerun-if-changed=CSFML
  cargo:rerun-if-env-changed=SFML_INCLUDE_DIR
  cargo:rerun-if-env-changed=SFML_LIBS_DIR
  TARGET = Some("x86_64-apple-darwin")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-apple-darwin")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
   running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-I" "CSFML/src/" "-I" "CSFML/include/" "-Wall" "-Wextra" "-DCSFML_SYSTEM_EXPORTS" "-DCSFML_AUDIO_EXPORTS" "-DCSFML_WINDOW_EXPORTS" "-DCSFML_GRAPHICS_EXPORTS" "-o" "/Users/dennisping/Documents/RustProjects/sfml_learn/vendors/rust-sfml/target/debug/build/sfml-c9ce53e953a58ee2/out/CSFML/src/System/Clock.o" "-c" "CSFML/src/System/Clock.cpp"
  exit status: 0
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-I" "CSFML/src/" "-I" "CSFML/include/" "-Wall" "-Wextra" "-DCSFML_SYSTEM_EXPORTS" "-DCSFML_AUDIO_EXPORTS" "-DCSFML_WINDOW_EXPORTS" "-DCSFML_GRAPHICS_EXPORTS" "-o" "/Users/dennisping/Documents/RustProjects/sfml_learn/vendors/rust-sfml/target/debug/build/sfml-c9ce53e953a58ee2/out/CSFML/src/System/Sleep.o" "-c" "CSFML/src/System/Sleep.cpp"
  exit status: 0
  cargo:warning=CSFML/src/Graphics/CircleShape.cpp:110:26: warning: 'sfCircleShape_getTransform' has C-linkage specified, but returns user-defined type 'sf::Transform' which is incompatible with C [-Wreturn-type-c-linkage]
  cargo:warning=extern "C" sf::Transform sfCircleShape_getTransform(const sf::CircleShape *shape) {
  cargo:warning=                         ^
  cargo:warning=CSFML/src/Graphics/CircleShape.cpp:114:26: warning: 'sfCircleShape_getInverseTransform' has C-linkage specified, but returns user-defined type 'sf::Transform' which is incompatible with C [-Wreturn-type-c-linkage]
  cargo:warning=extern "C" sf::Transform sfCircleShape_getInverseTransform(const sf::CircleShape *shape) {
  cargo:warning=                         ^
  cargo:warning=2 warnings generated.
  exit status: 0
crumblingstatue commented 3 years ago

The section you labeled error output doesn't actually contain any error output. Just random samples from the build output, none of which are errors.

Seeing the actual error messages would be nice, but my suspicion is that SFML cannot be found.

Try setting the environment variables SFML_INCLUDE_DIR to the include folder of your SFML install, and SFML_LIBS_DIR to where the compiled SFML library files are installed.

DennisPing commented 3 years ago

I tried some hacky methods. It would be nice if I could type SFML_INCLUDE_DIR right into the build.rs file but I cannot figure out the syntax (since I'm a beginner).

I hardcoded the paths to my system's .zshrc file

export SFML_INCLUDE_DIR="/usr/local/Cellar/sfml/2.5.1_1/include"
export SFML_LIBS_DIR="/usr/local/Cellar/sfml/2.5.1_1/lib"
export CSFML_INCLUDE_DIR="/usr/local/Cellar/csfml/2.5.1/include"
export CSFML_LIBS_DIR="/usr/local/Cellar/csfml/2.5.1/lib"

And my system can definitely find it as it pops up in the terminal autocomplete.

error: failed to run custom build command for `sfml v0.16.0 (/Users/dennisping/Documents/RustProjects/sfml_learn/vendors/rust-sfml)`

Caused by:
  process didn't exit successfully: `/Users/dennisping/Documents/RustProjects/sfml_learn/vendors/rust-sfml/target/debug/build/sfml-8082cf04abca3046/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=CSFML
  cargo:rerun-if-env-changed=SFML_INCLUDE_DIR
  cargo:rerun-if-env-changed=SFML_LIBS_DIR
  cargo:warning=Custom SFML include dir: /usr/local/Cellar/sfml/2.5.1_1/include
  TARGET = Some("x86_64-apple-darwin")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-apple-darwin")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-I" "CSFML/src/" "-I" "CSFML/include/" "-I" "/usr/local/Cellar/sfml/2.5.1_1/include/sfml" "-Wall" "-Wextra" "-DCSFML_SYSTEM_EXPORTS" "-DCSFML_AUDIO_EXPORTS" "-DCSFML_WINDOW_EXPORTS" "-DCSFML_GRAPHICS_EXPORTS" "-o" "/Users/dennisping/Documents/RustProjects/sfml_learn/vendors/rust-sfml/target/debug/build/sfml-c9ce53e953a58ee2/out/CSFML/src/System/Clock.o" "-c" "CSFML/src/System/Clock.cpp"
  exit status: 0
... (build output omitted)
DennisPing commented 3 years ago

Sorry to spam more... I am triple checking the Wiki and I can run the starter code perfectly: https://github.com/fabienjuif/rust-sfml-starter

I don't even need to export any LIBRARY paths for sfml or csfml. cargo run just builds successfully. So the issue isn't finding sfml.

My focus is now on bindgen and libclang

crumblingstatue commented 3 years ago

rust-sfml-starter uses a stable version of rust-sfml, which doesn't yet use libclang and bindgen, so it's a possibility those are your issue. The error output doesn't show much of use unfortunately, other than the build script failing, which could indeed be due to some issue with libclang and bindgen.

DennisPing commented 3 years ago

I appreciate your help. It seems to be a bug out of my control, so I won't push the issue any further. Thank you.