ImHex icon indicating copy to clipboard operation
ImHex copied to clipboard

[Bug] Cannot start on FreeBSD

Open alexax66 opened this issue 6 months ago • 4 comments

Operating System

FreeBSD 14.2

What's the issue you encountered?

I successful built ImHex on FreeBSD, but it can't start:

[14:05:23] [INFO]  [main | Main]               Welcome to ImHex 1.38.0.WIP-Debug!
[14:05:23] [INFO]  [main | Main]               Compiled using commit master@d33fad9
[14:05:23] [INFO]  [main | Main]               Running on FreeBSD 14.2-RELEASE-p2 FreeBSD 14.2-RELEASE-p2 n230744-26127ca9fef GENERIC (amd64)
[14:05:23] [INFO]  [main | Main]               FreeBSD distribution: GhostBSD 25.01-R14.2p2. Version: 25.01
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  18 (X_ChangeProperty)
  Resource id in failed request:  0x5800007
  Serial number of failed request:  123
  Current serial number in output stream:  132

How can the issue be reproduced?

Need some fixes for building:

  1. ImHex/lib/external/libwolv/libs/io/source/io/file_unix.cpp
diff --git a/libs/io/source/io/file_unix.cpp b/libs/io/source/io/file_unix.cpp
index c15fe79..a6467f4 100644
--- a/libs/io/source/io/file_unix.cpp
+++ b/libs/io/source/io/file_unix.cpp
@@ -8,6 +8,10 @@
 #if defined(OS_MACOS)
     #include <sys/types.h>
     #include <sys/event.h>
+#elif defined(OS_FREEBSD)
+    #include <sys/types.h>
+    #include <sys/event.h>
+    #include <poll.h>
 #elif defined(OS_LINUX)
     #include <sys/types.h>
     #include <sys/inotify.h>
@@ -194,7 +198,7 @@ namespace wolv::io {
     }


-    #if defined(OS_MACOS)
+    #if defined(OS_MACOS) || defined(OS_FREEBSD)
         void ChangeTracker::trackImpl(const bool &stopped, const std::fs::path &path, const std::function<void()> &callback) {
             int queue = kqueue();
             if (queue == -1)

  1. ImHex/main/gui/source/messaging/linux.cpp
diff --git a/main/gui/source/messaging/linux.cpp b/main/gui/source/messaging/linux.cpp
index a25c0f5b..44ec2a87 100644
--- a/main/gui/source/messaging/linux.cpp
+++ b/main/gui/source/messaging/linux.cpp
@@ -2,6 +2,7 @@
 
 #include <stdexcept>
 #include <fcntl.h>
+#include <unistd.h>
 #include <sys/file.h>
 
 #include <hex/helpers/logger.hpp>

  1. ImHex/main/gui/source/main.cpp b/main/gui/source/main.cpp
diff --git a/main/gui/source/main.cpp b/main/gui/source/main.cpp
index a6719076..34bce3fe 100644
--- a/main/gui/source/main.cpp
+++ b/main/gui/source/main.cpp
@@ -51,7 +51,11 @@ int main(int argc, char **argv) {
     log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash());
     log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture());
 
-    #if defined(OS_LINUX)
+    #if defined(OS_FREEBSD)
+        if (auto distro = ImHexApi::System::getLinuxDistro(); distro.has_value()) {
+            log::info("FreeBSD distribution: {}. Version: {}", distro->name, distro->version == "" ? "None" : distro->version);
+        }
+    #elif defined(OS_LINUX)
         if (auto distro = ImHexApi::System::getLinuxDistro(); distro.has_value()) {
             log::info("Linux distribution: {}. Version: {}", distro->name, distro->version == "" ? "None" : distro->version);
         }

Then start building:

CC=gcc14 CXX=g++14 cmake -G "Ninja"  -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="/usr/local" ..
ninja

ImHex Version

1.38.0.WIP

ImHex Build Type

  • [x] Nightly or built from sources

Installation type

Built from sources

Additional context?

FreeBSD ghostbsd-pc 14.2-RELEASE-p2 FreeBSD 14.2-RELEASE-p2

Desktop Environment: MATE 1.28.2

gcc14 --version
gcc14 (FreeBSD Ports Collection) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++14 --version
g++14 (FreeBSD Ports Collection) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

alexax66 avatar May 09 '25 11:05 alexax66

Hey! FreeBSD is not really supported by us. There have been some patches over the years to make it build but we don't have a CI or anything to ensure it stays that way. I also personally haven't ever run it on FreeBSD.

The issue you're seeing is probably due to some option passed to glfw which isn't supported on FreeBSD, which one I cannot tell you. You can try removing some of the window hints here and see if it works for you then: https://github.com/WerWolv/ImHex/blob/master/main/gui/source/init/splash_window.cpp#L434-L463. Most of them aren't necessary for the window to render in some way. Same changes will need to be done to the main window as well if you get the Splash Screen to show up

WerWolv avatar May 09 '25 12:05 WerWolv

OK, i will try

alexax66 avatar May 09 '25 12:05 alexax66

Hello, I'm encountering the same issue running on Ubuntu 22.04.

Njinx avatar May 13 '25 20:05 Njinx

I think need use Wayland

alexax66 avatar May 15 '25 14:05 alexax66

This may be the same as #2215, I ran into that on my system and filed a PR. I commented on that issue with a workaround that may also work for this issue.

iwanders avatar Aug 08 '25 23:08 iwanders

Yes, this patch is fine fix for splash window Image

But imhex terminated by signal SIGABRT (Abort) imhex.log

Need other patches for FreeBSD

alexax66 avatar Aug 10 '25 17:08 alexax66

Thanks for confirming it fixes the splash window issue, it's a start :)

iwanders avatar Aug 10 '25 18:08 iwanders

@alexax66 Please try to build and run the latest commits I just made. ImHex now fully compiles and runs without any patches on FreeBSD 14.3 for me.

WerWolv avatar Aug 10 '25 20:08 WerWolv

WerWolv I built imhex with latest commits without any other patches on FreeBSD 14.3 and GhostBSD 25.01 (based on FreeBSD 14.2-RELEASE-p3) and have the identical results:

  1. Splash window is appeared
  2. ImHex terminated by signal SIGTRAP (Trace or breakpoint trap):

imhex_FreeBSD.log imhex_GhostBSD.log

Please send me what did you do step by step

alexax66 avatar Aug 11 '25 19:08 alexax66

Hmm those error logs make very little sense to me. They point to somewhere inside of libfmt but nothing specific...

All I did was install the latest FreeBSD release from an iso, installed the required dependencies and built it using:

mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
ninja

WerWolv avatar Aug 11 '25 19:08 WerWolv

I made the same. It's strange. I will fresh install FreeBSD 14.3 and test again

alexax66 avatar Aug 11 '25 19:08 alexax66

I think that my FreeBSD 14.3 is the uncleaner after lot of major updates from version 13.2

alexax66 avatar Aug 11 '25 19:08 alexax66

WerWolv I sucsessfully built and runed ImHex after switch to LLVM 20 (clang 20.1.7)

Image
[00:11:12] [INFO]  [main | Main]                Welcome to ImHex 1.38.0.WIP!
[00:11:12] [INFO]  [main | Main]                Compiled using commit master@e9d95c7
[00:11:12] [INFO]  [main | Main]                Running on FreeBSD 14.2-RELEASE-p3 FreeBSD 14.2-RELEASE-p3 n230745-0d45d18c8cd GENERIC (amd64)
[00:11:12] [INFO]  [main | Main]                Linux distribution: GhostBSD 25.01-R14.2p3. Version: 25.01
[00:11:12] [INFO]  [main | Main]                Native scaling set to: 1.0
[00:11:13] [INFO]  [main | Main]                Using 'NVIDIA Corporation' GPU
[00:11:13] [INFO]  [main | Init Tasks]          Task 'Setting up environment' finished successfully in 0 ms
[00:11:13] [INFO]  [main | Init Tasks]          Task 'Creating directories' finished successfully in 20 ms
[00:11:13] [INFO]  [main | Init Tasks]          Task 'Loading settings' finished successfully in 0 ms
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'fonts.hexpluglib'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'ui.hexpluglib'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'hashes.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'builtin.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'decompress.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'yara_rules.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'diffing.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'visualizers.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'disassembler.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'remote.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Loading plugin 'script_loader.hexplug'
[00:11:13] [INFO]  [main | Init Tasks]          Library 'fonts.hexpluglib' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Library 'ui.hexpluglib' initialized successfully
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting auto_extract/workspaces/default.hexws to /home/alexax/.local/share/imhex/workspaces/default.hexws
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting auto_extract/workspaces/default.hexws to /usr/local/share/imhex/workspaces/default.hexws
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting auto_extract/workspaces/default.hexws to /usr/share/imhex/workspaces/default.hexws
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting auto_extract/workspaces/minimal.hexws to /home/alexax/.local/share/imhex/workspaces/minimal.hexws
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting auto_extract/workspaces/minimal.hexws to /usr/local/share/imhex/workspaces/minimal.hexws
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting auto_extract/workspaces/minimal.hexws to /usr/share/imhex/workspaces/minimal.hexws
[00:11:13] [INFO]  [builtin | Init Tasks]       Extracting always_auto_extract/magic/magic.mgc to /home/alexax/.local/share/imhex/magic/magic.mgc
[00:11:13] [INFO]  [main | Init Tasks]          Layout unlocked
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'builtin.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'decompress.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'diffing.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'disassembler.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'hashes.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'remote.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'script_loader.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'visualizers.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Plugin 'yara_rules.hexplug' initialized successfully
[00:11:13] [INFO]  [main | Init Tasks]          Task 'Loading plugins' finished successfully in 411 ms
[00:11:13] [INFO]  [main | Init Tasks]          Task 'Load Window Settings' finished successfully in 0 ms
[00:11:13] [INFO]  [main | Init Tasks]          Task 'Configuring UI scale' finished successfully in 0 ms
[00:11:13] [INFO]  [main | Checking for updat]  Task 'Checking for updates' finished successfully in 0 ms
[00:11:13] [INFO]  [main | Init Tasks]          ImHex fully started in 443ms
[00:11:13] [INFO]  [main | Main]                Switching to workspace 'Default'
[00:11:13] [INFO]  [main | Main]                Switching to workspace 'Default'
[00:11:13] [INFO]  [main | Main]                Updating workspace
[00:11:13] [ERROR] [main | Update Check]        Exception in task 'Update Check': collate_byname<char>::collate_byname failed to construct for C/ru_RU.UTF-8/C/C/C/C
[00:11:13] [ERROR] [main | Main]                Exception thrown in Task 'Update Check':

collate_byname<char>::collate_byname failed to construct for C/ru_RU.UTF-8/C/C/C/C

My steps:

alexax@ghostbsd-pc# sudo pkg install llvm20
alexax@ghostbsd-pc# clang20 --version
clang version 20.1.7
Target: x86_64-portbld-freebsd14.2
Thread model: posix
InstalledDir: /usr/local/llvm20/bin
alexax@ghostbsd-pc# CC=/usr/local/llvm20/bin/clang  CXX=/usr/local/llvm20/bin/clang++  \
cmake -G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="/usr/local" ..
ninja

alexax66 avatar Aug 11 '25 21:08 alexax66

@alexax66 Awesome! Glad it finally worked for you! Weird that gcc caused issues for you though. Both the Windows and Linux builds are all done with gcc, though it's gcc 15 in our case. I did compile using clang yesterday too because I was under the impression that that was the standard for FreeBSD

I'll close this issue for now then. If there's any more problems with FreeBSD cropping up, feel free to open a new issue and I'll take another look. Thanks a lot for your help and patience

WerWolv avatar Aug 11 '25 21:08 WerWolv