artur0513 / sem3_cpp_salaridze

0 stars 0 forks source link

The project fails to be built at Linux #1

Open makaleks opened 1 year ago

makaleks commented 1 year ago

The project failed to be built at Linux. Here I attach the diff I had to apply to make the project working. The main problems:

diff --git a/stE-project/CMakeLists.txt b/stE-project/CMakeLists.txt
index a7e9744..0de23e1 100644
--- a/stE-project/CMakeLists.txt
+++ b/stE-project/CMakeLists.txt
@@ -14,13 +14,26 @@ add_subdirectory(SFML_dir SFML)
 include_directories(./src)
 include_directories(./src/headers)

-target_link_libraries(stE-project sfml-graphics sfml-system sfml-main)
+target_link_libraries(stE-project sfml-graphics sfml-system)
+if (WIN32)
+    # sfml-main does not occur at linux, this lib exists for WinMain only
+    # Looks strange that sfml does not present the module as universal wrapper
+    # So there might be a better solution
+    target_link_libraries(stE-project sfml-main)
+endif()
 target_compile_features(stE-project PUBLIC cxx_std_20)
+#set(CMAKE_CXX_STANDARD 20)

 if (BUILD_TESTING) #тест
 add_executable (stE-testing "test.cpp" "Car.cpp" "Car.h" "simple-opengl-loader.h" "Common.cpp" "Common.h" "Console.cpp" "Console.h" "Graphics.cpp" "Graphics.h"
                            "LevelGenerator.cpp" "LevelGenerator.h" "Weather.cpp" "Weather.h")
-target_link_libraries(stE-testing sfml-graphics sfml-system sfml-main)
+target_link_libraries(stE-testing sfml-graphics sfml-system)
+if (WIN32)
+    # sfml-main does not occur at linux, this lib exists for WinMain only
+    # Looks strange that sfml does not present the module as universal wrapper
+    # So there might be a better solution
+    target_link_libraries(stE-testing sfml-main)
+endif()
 target_compile_features(stE-testing PUBLIC cxx_std_20)
 add_test(FirstTest stE-testing)
 set_tests_properties(FirstTest PROPERTIES
diff --git a/stE-project/Common.cpp b/stE-project/Common.cpp
index fbce9fe..cfbd667 100644
--- a/stE-project/Common.cpp
+++ b/stE-project/Common.cpp
@@ -1,6 +1,10 @@
 #pragma once
 #include "Common.h"

+#include <time.h>
+using namespace std;
+
+#define localtime_s(timeinfo_ptr, seconds_ptr) *(timeinfo_ptr) = *localtime(seconds_ptr)

 string get_date_string() {
    char buffer[80];
@@ -96,4 +100,4 @@ void Game_time::load_from_file(ifstream& file) {
    file >> year >> month >> day >> hour >> second >> total_seconds;
    total_hours = double(total_seconds) / 3600.0;
    day_hours = fmod(total_hours, 24.0);
-}
\ No newline at end of file
+}
diff --git a/stE-project/Common.h b/stE-project/Common.h
index 1a61a91..63dd3e1 100644
--- a/stE-project/Common.h
+++ b/stE-project/Common.h
@@ -4,7 +4,7 @@
 #include <iostream>
 #include <cmath>
 #include <string>
-#include <conio.h>
+//#include <conio.h>
 #include <fstream>
 #include <map>
 #include <deque>
diff --git a/stE-project/Graphics.cpp b/stE-project/Graphics.cpp
index 8cf3bc0..93dd52b 100644
--- a/stE-project/Graphics.cpp
+++ b/stE-project/Graphics.cpp
@@ -199,7 +199,8 @@ void gr::Sprite_object::load_from_file(ifstream& file) {
        delta_layer = -1000.0;
        current_sprite = &def_sprite;
    }
-   file.exceptions(0);
+   //file.exceptions(0);
+   file.exceptions(std::ios::goodbit);
 }

 // Сохранение спрайта в файл
@@ -292,7 +293,8 @@ void gr::Effect::load_from_file(ifstream& file) {
        Console::get_instance()->log("Error while loading effect, config file may have incorrect structure", ConsoleMessageType::ERR);
        bad_load = true;
    }
-   file.exceptions(0);
+   //file.exceptions(0);
+   file.exceptions(std::ios::goodbit);
 }

 // Создание спрайта эффекта на основе текстуры на которую эффект будет накладываться
@@ -414,7 +416,8 @@ void gr::Light_source::load_from_file(ifstream& file) {
        colors.push_back(pair<Vector3f, Time>(Vector3f(1.f, 0.f, 0.f), full_animation_time));
    }

-   file.exceptions(0);
+   //file.exceptions(0);
+   file.exceptions(std::ios::goodbit);
 }

 void gr::Light_source::print_info() {
makaleks commented 1 year ago

The other problem is that localtime_s is Optional to be implemented, and at linux it isn't. Moreover, it's interface at standard is different from Microsoft's implementation.