josevcm / nfc-laboratory

NFC signal and protocol analyzer using SDR receiver
GNU General Public License v3.0
411 stars 47 forks source link

Linux support #22

Closed olafium closed 1 year ago

olafium commented 1 year ago

Found this project mentioned on Hackaday, congratulations. I wish to try it out myself, but sadly I don't use Windows.

I'm aware it's windows-only, but I tried my luck with compiling it on Linux (QT Creator 9.0.2) and the error was following:

src/nfc-lib/lib-rt/rt-lang/src/main/cpp/Logger.cpp:241: error: ‘localtime_s’ was not declared in this scope; did you mean ‘localtime_r’?
src/nfc-lib/lib-rt/rt-lang/src/main/cpp/Logger.cpp: In member function ‘void rt::LogWriter::write(rt::LogEvent*)’:
src/nfc-lib/lib-rt/rt-lang/src/main/cpp/Logger.cpp:241:7: error: ‘localtime_s’ was not declared in this scope; did you mean ‘localtime_r’?
  241 |       localtime_s(&timeinfo, &seconds);
      |       ^~~~~~~~~~~
      |       localtime_r

Since I'm not big on C, I have no idea how difficult it would be. However I am willing to test out any possible future developments. (If it matters, the exact distro is debian sid)

Cheers

josevcm commented 1 year ago

Hello,

This line is for logging purposes only, try commenting it out with // and recompile. If you found more than one line with this, do the same.

// localtime_s(&timeinfo, &seconds);

Right now I don't have Linux Machine to verify this.

tommy-gilligan commented 1 year ago

I see the same thing on M2 Mac After commenting out localtime_s I get

1 warning generated.
[  4%] Building CXX object src/nfc-lib/lib-rt/rt-lang/CMakeFiles/rt-lang.dir/src/main/cpp/FileSystem.cpp.o
clang: warning: argument unused during compilation: '-msse' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-msse3' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mno-avx' [-Wunused-command-line-argument]
/Users/tom/nfc-laboratory/src/nfc-lib/lib-rt/rt-lang/src/main/cpp/FileSystem.cpp:69:8: error: no matching function for call to 'mkdir'
   if (mkdir(path.c_str()) < 0)
       ^~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/sys/stat.h:384:9: note: candidate function not viable: requires 2 arguments, but 1 was provided
int     mkdir(const char *, mode_t);
        ^
1 error generated.
make[2]: *** [src/nfc-lib/lib-rt/rt-lang/CMakeFiles/rt-lang.dir/src/main/cpp/FileSystem.cpp.o] Error 1
make[1]: *** [src/nfc-lib/lib-rt/rt-lang/CMakeFiles/rt-lang.dir/all] Error 2
make: *** [all] Error 2

After commenting out mkdir call I get

[  1%] Building CXX object src/nfc-lib/lib-rt/rt-lang/CMakeFiles/rt-lang.dir/src/main/cpp/FileSystem.cpp.o
clang: warning: argument unused during compilation: '-msse' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-msse3' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mno-avx' [-Wunused-command-line-argument]
[  2%] Linking CXX static library librt-lang.a
[  7%] Built target rt-lang
[  7%] Building C object src/nfc-lib/lib-ext/airspy/CMakeFiles/airspy.dir/src/main/c/airspy.c.o
clang: warning: argument unused during compilation: '-msse' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-msse3' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mno-avx' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
[  8%] Building C object src/nfc-lib/lib-ext/airspy/CMakeFiles/airspy.dir/src/main/c/iqconverter_float.c.o
clang: warning: argument unused during compilation: '-msse' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-msse3' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mno-avx' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:127:2: error: use of undeclared identifier '__m128'
        __m128 acc = _mm_set_ps(0, 0, 0, 0);
        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:143:4: error: use of undeclared identifier '__m128'
                        __m128 head1 = _mm_loadu_ps(queue);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:144:4: error: use of undeclared identifier '__m128'
                        __m128 kern1 = _mm_load_ps(kernel);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:145:4: error: use of undeclared identifier '__m128'
                        __m128 head2 = _mm_loadu_ps(queue + 4);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:146:4: error: use of undeclared identifier '__m128'
                        __m128 kern2 = _mm_load_ps(kernel + 4);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:148:4: error: use of undeclared identifier '__m128'
                        __m128 mul1 = _mm_mul_ps(kern1, head1);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:149:4: error: use of undeclared identifier '__m128'
                        __m128 mul2 = _mm_mul_ps(kern2, head2);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:151:4: error: use of undeclared identifier 'mul1'
                        mul1 = _mm_add_ps(mul1, mul2);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:151:11: error: call to undeclared function '_mm_add_ps'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                        mul1 = _mm_add_ps(mul1, mul2);
                               ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:151:22: error: use of undeclared identifier 'mul1'
                        mul1 = _mm_add_ps(mul1, mul2);
                                          ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:151:28: error: use of undeclared identifier 'mul2'
                        mul1 = _mm_add_ps(mul1, mul2);
                                                ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:153:4: error: use of undeclared identifier 'acc'
                        acc = _mm_add_ps(acc, mul1);
                        ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:153:21: error: use of undeclared identifier 'acc'
                        acc = _mm_add_ps(acc, mul1);
                                         ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:153:26: error: use of undeclared identifier 'mul1'
                        acc = _mm_add_ps(acc, mul1);
                                              ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:185:3: error: use of undeclared identifier '__m128'
                __m128 head = _mm_loadu_ps(queue);
                ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:186:3: error: use of undeclared identifier '__m128'
                __m128 kern = _mm_load_ps(kernel);
                ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:187:3: error: use of undeclared identifier '__m128'
                __m128 mul = _mm_mul_ps(kern, head);
                ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:188:3: error: use of undeclared identifier 'acc'
                acc = _mm_add_ps(acc, mul);
                ^
/Users/tom/nfc-laboratory/src/nfc-lib/lib-ext/airspy/src/main/c/iqconverter_float.c:188:9: error: call to undeclared function '_mm_add_ps'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                acc = _mm_add_ps(acc, mul);
                      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [src/nfc-lib/lib-ext/airspy/CMakeFiles/airspy.dir/src/main/c/iqconverter_float.c.o] Error 1
make[1]: *** [src/nfc-lib/lib-ext/airspy/CMakeFiles/airspy.dir/all] Error 2
make: *** [all] Error 2

I also have Linux on ARM and Linux on Intel NUC It looks like this needs SSE3 so I might try on Intel NUC later

josevcm commented 1 year ago

I'm very sorry for the inconvenience, this project was designed for X86 architecture, I don't have a MAC to test it and see if it's possible to fix it.

josevcm commented 1 year ago

Found this project mentioned on Hackaday, congratulations. I wish to try it out myself, but sadly I don't use Windows.

I'm aware it's windows-only, but I tried my luck with compiling it on Linux (QT Creator 9.0.2) and the error was following:

src/nfc-lib/lib-rt/rt-lang/src/main/cpp/Logger.cpp:241: error: ‘localtime_s’ was not declared in this scope; did you mean ‘localtime_r’?
src/nfc-lib/lib-rt/rt-lang/src/main/cpp/Logger.cpp: In member function ‘void rt::LogWriter::write(rt::LogEvent*)’:
src/nfc-lib/lib-rt/rt-lang/src/main/cpp/Logger.cpp:241:7: error: ‘localtime_s’ was not declared in this scope; did you mean ‘localtime_r’?
  241 |       localtime_s(&timeinfo, &seconds);
      |       ^~~~~~~~~~~
      |       localtime_r

Since I'm not big on C, I have no idea how difficult it would be. However I am willing to test out any possible future developments. (If it matters, the exact distro is debian sid)

Cheers

Hi

Please check the development branch again, I added some changes to support linux build, but it was only tested with my WSL2 distro on windows, I don't know if it would work well on native linux.

tommy-gilligan commented 1 year ago

Thank you for the changes. I would have never figured out that segfault.

I've been able to get nfc-laboratory to compile on aarch64 Linux https://github.com/tomgilligan/nfc-laboratory/tree/arm . It launches to a blank screen though. I appreciate that ARM support is probably not a priority but I think some of the changes I needed to compile under Linux are relevant for x86 Linux.

tommy-gilligan commented 1 year ago

Also worth mentioning: despite the program drawing a blank window, you can still interact with it eg. by blindly clicking where the toolbar buttons should be.

tommy-gilligan commented 1 year ago

I just now tested your develop branch on x86-64 Linux. At first it would hang in a poll on init. Then I tried adding sudo and got a blank window like aarch64 Linux.

I am running different distro between these machines, so that's probably enough of a reason for different permissions being necessary. Overall I think this is quite encouraging.

tommy-gilligan commented 1 year ago

I'm able to get a window showing by commenting out some window configuration in QTWindow.cpp

   // configure window properties
   // setAttribute(Qt::WA_OpaquePaintEvent, true);
   // setAttribute(Qt::WA_PaintOnScreen, true);
   // setAttribute(Qt::WA_DontCreateNativeAncestors, true);
   // setAttribute(Qt::WA_NativeWindow, true);
   // setAttribute(Qt::WA_NoSystemBackground, true);
   // setAutoFillBackground(false);
tommy-gilligan commented 1 year ago

narrowed it down to

setAttribute(Qt::WA_PaintOnScreen, true);

sorry for the frequent messasges

josevcm commented 1 year ago

Thanks for your help Tommy, great Job!

I will integrate the changes you propose as soon as possible.

tommy-gilligan commented 1 year ago

For the record, I have it working on Mac. One of the main things necessary is to support ARM in FFT (or even just opt out of SIMD for ARM). https://github.com/Pflugshaupt/muFFT is a fork of the muFFT currently used by NFC Laboratory that works but I'm wondering if long-term it is better to switch to FFTW? With that caveat, I'll open a PR for muFFT fork.

josevcm commented 1 year ago

Thanks for trying it on MAC Tom, for the moment I will disable the SMID instructions so that they only apply on x86.

The FFT display is not the main functionality of nfc-laboratory, and really not very useful I think. Select muFFT because of its simplicity and easy compilation, plus the MIT license.

tommy-gilligan commented 1 year ago
target_compile_options(airspy PRIVATE "-msse2" -DUSE_SSE2)

in src/nfc-lib/lib-ext/airspy/CMakeLists.txt also needs to be disabled for Arm

josevcm commented 1 year ago

Sorry for the delay, I have not yet been able to review your comments or the PR to integrate it, I have not forgotten. I'll do it when I have time.

josevcm commented 1 year ago
target_compile_options(airspy PRIVATE "-msse2" -DUSE_SSE2)

in src/nfc-lib/lib-ext/airspy/CMakeLists.txt also needs to be disabled for Arm

Please Tom, check again, I fixed the related problems with Linux Build in develop branch

Thanks