V: Linux being misidentified as macOS

Created on 23 Jun 2019  Â·  18Comments  Â·  Source: vlang/v

When running

$ ./vc -o v .

on Linux, I get the error:

cc: error: unrecognized command line option ‘-mmacosx-version-min=10.7’

In main.v I see

        if c.os == MAC {
                a << '-mmacosx-version-min=10.7'
        }

which indicates that my Linux machine is being misidentified as macOS.

(It also assumes that I'm compiling with clang but that's another issue.)

EDIT: the solution is to run

$ ./vc -os linux -o v .

to compile on Linux... which solves OS "detection" -- thank you to @superwhiskers for figuring this out! :+1: -- but I personally can't compile on Linux yet.

Bug

Most helpful comment

        // Cross compiling linux
        sysroot := '/Users/alex/tmp/lld/linuxroot/'

Jeez, more terrible hardcoding...

All 18 comments

ok so here's what i've deduced so far, @elimisteve
c.os is deduced using the a set of compile-time if expressions
here's the code that does that

    mut _os := MAC
    // No OS specifed? Use current system
    if target_os == '' {
        $if linux {
            _os = LINUX
        }
        $if mac {
            _os = MAC
        }
        $if windows {
            _os = WINDOWS
        }
    }
    else {
        switch target_os {
        case 'linux': _os = LINUX
        case 'windows': _os = WINDOWS
        case 'mac': _os = MAC
        }
    }

i'm still working on deducing what conditions are used to figure out the operating system. i'll update you if i find anything out

@superwhiskers Thanks :+1: . I've reached similar conclusions and can say that even compiling with clang does not help with the OS misindentification:

$ clang -std=c11 v.c -w -o vc && ./vc -o v .
cc: error: unrecognized command line option ‘-mmacosx-version-min=10.7’
V panic: clang error

yeah. clang wouldn't have anything to do with it though. it's probably some funky os detection stuff

I wouldn't be surprised if different compilers used different criteria to determine the OS they are running on at compile time, but I don't know how clang does it versus gcc; maybe they're the same.

ah ok. so it relies on the c compiler to do the os checking.
l2517-2530

        name := p.check_name()
        if name in SupportedPlatforms {
            if not {
                p.genln('#ifndef $name')
            }
            else {
                p.genln('#ifdef $name')
            }
            p.check(LCBR)
            p.statements_no_curly_end()
            if ! (p.tok == DOLLAR && p.peek() == ELSE) {
                p.genln('#endif')
            }
        }

so basically, your c compiler thinks you're on macos, or your c compiler doesn't think you're on macos, windows or linux and so it falls back to the default, macos

i'm not quite sure how you could fix this, but what exactly are you running

there's one quick hack you could do though which involves passing -os linux to the compiler which will override the os checking part

there's one quick hack you could do though which involves passing -os linux to the compiler which will override the os checking part

Any idea how to do that? Literally adding -os linux to clang or gcc doesn't work for me.

I see https://stackoverflow.com/a/8249232 ... Maybe <= that is how the OS detection logic should be implemented in the first place?

to the v compiler, not the c compiler

Ah. Well I get:

$ ./vc -os linux -o v .
cc: error: x86_64-linux-gnu: No such file or directory
cc: error: unrecognized command line option ‘-target’
V panic: clang error

You're right though -- that fixed OS "detection"! :tada: Thank you; well done.

you can now manually compile the v binary by running
```
clang -o v ~/.vlang*/compiler.c
````
(i think)

ah ok. np

        // Cross compiling linux
        sysroot := '/Users/alex/tmp/lld/linuxroot/'

Jeez, more terrible hardcoding...

oh yeah. there's a lot more than just that though :)

i've been working on fixing some of that but i decided to take a break to work on some of the issues in the issue tracker

On Linux, you can also compile v.c with:
gcc -Dlinux -g -std=c11 -w -o vc v.c

Should be fixed now by 0.1.0 . It now depends on C macros instead of random defines in the code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medvednikov picture medvednikov  Â·  3Comments

cjmxp picture cjmxp  Â·  3Comments

markgraydev picture markgraydev  Â·  3Comments

oleg-kachan picture oleg-kachan  Â·  3Comments

taojy123 picture taojy123  Â·  3Comments