vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.69k stars 2.15k forks source link

Including Homebrew's sshlib fails to compile #21692

Closed benash closed 3 months ago

benash commented 3 months ago

V doctor:

V full version: V 0.4.6 1a685c3
OS: macos, macOS, 13.6.7, 22G720
Processor: 12 cpus, 64bit, little endian, Apple M2 Pro

getwd: /Users/ben/git/scripts/vdi/v
vexe: /Users/ben/git/v/v
vexe mtime: 2024-06-17 19:40:40

vroot: OK, value: /Users/ben/git/v
VMODULES: OK, value: /Users/ben/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.3 (Apple Git-145)
Git vroot status: weekly.2024.24-14-g1a685c30
.git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.1.0.2.5)
thirdparty/tcc status: thirdparty-macos-arm64 5c1d002f

What did you do? v -g -o vdbg cmd/v && vdbg src/main.v

module main

// Import the C library
#flag darwin -I /opt/homebrew/include
#flag darwin -I ext
#flag darwin -L /opt/homebrew/lib
#flag -lssh
#include <libssh/libssh.h>

// Declare the C functions and types you need
struct C.ssh_session_struct {}

type Cssh_session = &C.ssh_session_struct

// Initialize a new SSH session
fn C.ssh_new() Cssh_session

// Free an SSH session
fn C.ssh_free(session Cssh_session)

// Connect to an SSH server
fn C.ssh_connect(session Cssh_session) int

// Set server host
fn C.ssh_options_set(session Cssh_session, option_type int, value voidptr) int

// Constants
const ssh_options_host = 0 // The option type for setting hostname, replace with actual constant from libssh

// Wrap the ssh_new function
fn ssh_new() &C.ssh_session_struct {
    return C.ssh_new()
}

// Wrap the ssh_free function
fn ssh_free(session &C.ssh_session_struct) {
    C.ssh_free(session)
}

// Wrap the ssh_connect function
fn ssh_connect(session &C.ssh_session_struct) int {
    return C.ssh_connect(session)
}

// Wrap the ssh_options_set function for setting hostname
fn ssh_set_host(session &C.ssh_session_struct, host string) int {
    return C.ssh_options_set(session, ssh_options_host, host.str)
}

fn main() {
    // Example usage
    session := ssh_new()
    if session == unsafe { nil } {
        println('Failed to create session')
        return
    }

    // Set the host
    if ssh_set_host(session, $env('ssh_host')) != 0 {
        println('Failed to set host')
        ssh_free(session)
        return
    }

    // Connect
    if ssh_connect(session) != 0 {
        println('Connection failed')
    } else {
        println('Connected successfully')
    }

    // Clean up
    ssh_free(session)
}

What did you expect to see?

Successful compilation

What did you see instead?

==================
/tmp/v_501/main.01J0M58M18T5E4D86MFNTGFDWY.tmp.c:1888:6: error: conflicting types for 'string_free'
void string_free(string* s);
     ^
/opt/homebrew/include/libssh/legacy.h:118:32: note: previous declaration is here
SSH_DEPRECATED LIBSSH_API void string_free(ssh_string str);
                               ^
/tmp/v_501/main.01J0M58M18T5E4D86MFNTGFDWY.tmp.c:4350:5: warning: 'string_free' is deprecated [-Wdeprecated-declarations]
                                string_free(&s);
                                ^
/opt/homebrew/include/libssh/legacy.h:118:1: note: 'string_free' has been explicitly marked deprecated here
SSH_DEPRECATED LIBSSH_API void string_free(ssh_string str);
^
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

benash commented 3 months ago

Looks like a dup of #13890