Other Issues with clang / GNUstep

Hello everyone,

To explain the problem, I'm on a Dell Optiflex 5270 AIO series, I installed FreeBSD for use without Internet (it's an obligation imposed by my work environment) I still have Internet access on another Windows machine. So I gradually installed my development environment with the aim of compiling objective C.

I'm not a FreeBSD professional, my experience is limited to using Linux, so please excuse me if I don't use it properly for the first time.

Offline, I have two ways of installing packages:
- Via ports
- Via pkg install ‘package_name’.

So little by little I installed Gnome, sublimeText and GNUstep (make, back, base and tried to compile with clang a simple program that displays Hello World!

There's the programme :
Code:
#import <Foundation/Foundation.h>
/*
int main(int argc, const char * argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, World!");
    }
    return 0;
}
*/

Don't pay too much attention to the code itself as I don't yet know the difference between version 1 and 2 of objective C, I just wanted to compile without errors by first importing a GNUstep library

And How i try to compile it :
Code:
clang -V -I/usr/local/include/objc \
      -I/usr/local/GNUstep/System/Library/Headers \
      -L/usr/local/GNUstep/System/Library/Libraries \
      -lgnustep-base -fconstant-string-class=NSConstantString \
      -o HelloWorld hello.m

I've got an error that says :
Code:
root@dell-pc:/objectiveCproject/helloWorld # clang -v -I/usr/local/include/objc
\
      -I/usr/local/GNUstep/System/Library/Headers \
      -L/usr/local/GNUstep/System/Library/Libraries \
      -lgnustep-base -fconstant-string-class=NSConstantString -fobjc-nonfragile-abi \
      -o HelloWorld hello.m
FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang" -cc1 -triple x86_64-unknown-freebsd14.0 -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hello.m -mrelocation-model static -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/objectiveCproject/helloWorld -resource-dir /usr/lib/clang/16 -I /usr/local/include/objc -I /usr/local/GNUstep/System/Library/Headers -internal-isystem /usr/lib/clang/16/include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/objectiveCproject/helloWorld -fconstant-string-class NSConstantString -ferror-limit 19 -fgnuc-version=4.2.1 -fobjc-runtime=gnustep -fobjc-encode-cxx-class-template-spec -fobjc-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/hello-a20631.o -x objective-c hello.m
clang -cc1 version 16.0.6 based upon LLVM 16.0.6 default target x86_64-unknown-freebsd14.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/objc
 /usr/local/GNUstep/System/Library/Headers
 /usr/lib/clang/16/include
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o HelloWorld /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/local/GNUstep/System/Library/Libraries -L/usr/lib -lgnustep-base /tmp/hello-a20631.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
ld: error: /usr/local/GNUstep/System/Library/Libraries/libgnustep-base.so is incompatible with /usr/lib/crt1.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My clang version :
Code:
root@dell-pc:/objectiveCproject/helloWorld # clang --version
FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin

I'd like to point out that I've tested clang with a C program and it compiles perfectly.

My FreeBSD :
Code:
 FreeBSD dell-pc 14.0-RELEASE FreeBSD 14.0-RELEASE #0 releng/14.0-n265380-f9716eee8ab4: Fri Nov 10 05:57:23 UTC 2023 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERICamd64

I tried to deinstall install GNUstep but nothing change, maybe I'm completely off the mark but I'm running out of ideas to solve this problem :(

I also tried with gcc but i've got problem with some ABI fragile :
Code:
/usr/local/GNUstep/System/Library/Headers/GNUstepBase/GSVersionMacros.h:294:6: error: #error "Your gnustep-base was configured for the objc-nonfragile-abi but you are not using it now."
  294 | #    error "Your gnustep-base was configured for the objc-nonfragile-abi but you are not using it now."
      |      ^~~~~
In file included from /usr/local/GNUstep/System/Library/Headers/objc/runtime.h:219,
                 from /usr/local/GNUstep/System/Library/Headers/objc/objc.h:1,
                 from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:31:
/usr/local/GNUstep/System/Library/Headers/objc/slot.h:31:1: sorry, unimplemented: '_Atomic' in Objective-C
   31 | OBJC_PUBLIC extern _Atomic(uint64_t) objc_method_cache_version;
      | ^~~~~~~~~~~

Thanks for your help
 
Maybe you need -fobjc-runtime=gnustep-2.0?

This source
Code:
#import <Foundation/Foundation.h>

int
main (void)
{ 
  NSLog (@"Executing");
  return 0;
}

Compiled for me with this shell command
Code:
clang\
 -fobjc-runtime=gnustep-2.0\
 -I /usr/local/include\
 -I /usr/local/GNUstep/System/Library/Headers\
 -L /usr/local/GNUstep/System/Library/Libraries\
 -lgnustep-base\
 -L /usr/local/lib\
 -lobjc\
 tool.m -o tool

And yielded a runnable executable
Code:
$ ./tool
2024-06-04 03:07:04.928 tool[2492:100902] No local time zone specified.
2024-06-04 03:07:04.928 tool[2492:100902] Using time zone with absolute offset 0.
2024-06-04 03:07:04.928 tool[2492:100902] Executing
 
Maybe you need -fobjc-runtime=gnustep-2.0?

This source
Code:
#import <Foundation/Foundation.h>

int
main (void)
{
  NSLog (@"Executing");
  return 0;
}

Compiled for me with this shell command
Code:
clang\
 -fobjc-runtime=gnustep-2.0\
 -I /usr/local/include\
 -I /usr/local/GNUstep/System/Library/Headers\
 -L /usr/local/GNUstep/System/Library/Libraries\
 -lgnustep-base\
 -L /usr/local/lib\
 -lobjc\
 tool.m -o tool

And yielded a runnable executable
Code:
$ ./tool
2024-06-04 03:07:04.928 tool[2492:100902] No local time zone specified.
2024-06-04 03:07:04.928 tool[2492:100902] Using time zone with absolute offset 0.
2024-06-04 03:07:04.928 tool[2492:100902] Executing
Thank you very much for the help, it seems that it is simply this line:
-fobjc-runtime=gnustep-2.0 instead of -lgnustep-base -fconstant-string-class=NSConstantString.

I tried with this code:
#import <Foundation/Foundation.h> int main (int argc, const char *argv[]) { NSString *str = @"Hello World"; fprintf(stdout, "%s",[str UTF8String]); return 0; }

and this command:
clang\ -fobjc-runtime=gnustep-2.0\ -I /usr/local/include\ -I /usr/local/GNUstep/System/Library/Headers\ -L /usr/local/GNUstep/System/Library/Libraries\ -lgnustep-base\ -L /usr/local/lib\ -lobjc\ hello.m -o hello

./Hello

And "Hello World" appears in my console.
 
I'm not an objective C programmer. But I found this which might give you a clue.

error "Your gnustep-base was configured for the objc-nonfragile-abi but you are not using it now.

Thank you for this answer, but I only have the problem with gcc, I will continue to use clang which corresponds more to my needs.

But the site you sent is a coherent lead that I haven't explored, thank you very much for your response.
 
Thank you very much for the help, it seems that it is simply this line:
-fobjc-runtime=gnustep-2.0 instead of -lgnustep-base -fconstant-string-class=NSConstantString.
You're welcome! The libobjc2 readme has a decent explanation of what the different runtime settings mean.

I tried with this code...
Yeah, NSLog is kind of obnoxious. I settled on this for my hello-world:
Code:
#import <GNUstepBase/GSObjCRuntime.h>

int main (void)
{
  GSPrintf(stdout, @"Hello World!\n");
  return 0;
}
It's compiled with the same command as before. I found GSPrintf() reading the GNUstep docs:
 
Back
Top