Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including Homebrew's sshlib fails to compile #21692

Closed
benash opened this issue Jun 17, 2024 · 1 comment
Closed

Including Homebrew's sshlib fails to compile #21692

benash opened this issue Jun 17, 2024 · 1 comment

Comments

@benash
Copy link

benash commented Jun 17, 2024

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
Copy link
Author

benash commented Jun 17, 2024

Looks like a dup of #13890

@benash benash closed this as completed Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant