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

Failed to compile when a piece of code include #pkgconfig #23064

Closed
abc-JYL opened this issue Dec 4, 2024 · 16 comments
Closed

Failed to compile when a piece of code include #pkgconfig #23064

abc-JYL opened this issue Dec 4, 2024 · 16 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@abc-JYL
Copy link

abc-JYL commented Dec 4, 2024

Describe the bug

I write a simple piece of code to make a c wrapper for tcl/tk
Code:

module tk

#pkgconfig tcl tk

// Define C stuff

The #pkgconfig line can't find zlib

Full error

src/lib.v:3:1: error: could not resolve dependency zlib
    1 | module tk
    2 |
    3 | #pkgconfig tcl tk
      | ~~~~~~~~~~~~~~~~~
    4 |
    5 | #include <tcl.h>

I found out that the standard pkg-config return none when pkg-config --cflags zlib

Reproduction Steps

Write a piece of code that included #pkgconfig

Expected Behavior

It should successfully compile and have zero problems.

Current Behavior

Currently, the V compile emit a error says: error: could not resolve dependency zlib

Possible Solution

I think there is some problem in the vlib.pkgconfig that did not handle the case that is not defined or filter out in the .pc files.

Additional Information/Context

error with zlib

src/lib.v:3:1: error: Cannot find "zlib" pkgconfig file
    1 | module tk
    2 |
    3 | #pkgconfig zlib
      | ~~~~~~~~~~~~~~~
    4 |
    5 | #include <tcl.h>

V version

Current V version: V 0.4.8 b103ce3, timestamp: 2024-12-04 14:11:21 +0200

Environment details (OS name and version, etc.)

Macbook Air M2 (2022)
8 GB of RAM
MacOs Version: Sonoma 14.1.1

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.

Huly®: V_0.6-21504

@abc-JYL abc-JYL added the Bug This tag is applied to issues which reports bugs. label Dec 4, 2024
@jorgeluismireles
Copy link

Did you try #pkgconfig --libs --cflags ...?

@abc-JYL
Copy link
Author

abc-JYL commented Dec 4, 2024

Did you try #pkgconfig --libs --cflags ...?

Yes, I did it also emit the same error.

@jorgeluismireles
Copy link

jorgeluismireles commented Dec 5, 2024

I found out that the standard pkg-config return none when pkg-config --cflags zlib

Same here, but next give me results:

$ pkg-config --modversion zlib
1.2.11
$ pkg-config --libs zlib
-lz

@jorgeluismireles
Copy link

jorgeluismireles commented Dec 5, 2024

In my system pkg-config --list-all did not show any tcl. I went to https://www.tcl-lang.org/doc/howto/compile.html#source and download the tcl 8.6. Then did configure, make, make install. Now pkg-config has the tcl:

$ pkg-config --list-all | grep tcl
tcl                            Tool Command Language - Tcl is a powerful, easy-to-learn dynamic programming language, suitable for a wide range of uses.
$ pkg-config --modversion tcl
8.6.15
$ pkg-config --libs tcl
-L/usr/local/lib -ltcl8.6 -ltclstub8.6
$ pkg-config --cflags tcl
-I/usr/local/include

Guess tk process is similar.

@abc-JYL
Copy link
Author

abc-JYL commented Dec 5, 2024

I found out that the standard pkg-config return none when pkg-config --cflags zlib

Same here, but next give me results:

$ pkg-config --modversion zlib
1.2.11
$ pkg-config --libs zlib
-lz

But pkg-config --cflags zlib return none

@jorgeluismireles
Copy link

But pkg-config --cflags zlib return none

I think pkg-config issues so far aren't related to V language until now but maybe a C compiler issue. I am also interested in tcl/tk, tkwas a very decent multi-platform GUI that predated Java and is very underrated in my opinion. Is very easy do small tk apps with python. I'll try to install tkand give it a try as a wrapper for V and report whatever I get to compare.

@jorgeluismireles
Copy link

C version

This is a small TCL interpreter called from C named tclsh.c:

# include <tcl.h>

int AppInit(Tcl_Interp *interp) {
	if (Tcl_Init(interp) == TCL_ERROR)
		return TCL_ERROR;
	Tcl_SetVar(interp, "tcl_rcFileName", "~/.wishrc", TCL_GLOBAL_ONLY);
	return TCL_OK;
}

int main(int argc, char *argv[]) {
	Tcl_Main(argc, argv, AppInit);
	return 0;
}

With my installation mentioned before compiles with

$ gcc tclsh.c -o tclsh -ltcl8.6

And run and the interpreter is functional (I entered a sum of numbers 1 and 2):

$ ./tclsh
% expr {1+2}
3
%

V version

Now this is my attemp to convert to V called tclsh.v:

module main

#pkgconfig --libs --cflags tcl

#include <tcl.h>

fn C.Tcl_Main(argc int, argv &&char, init &voidptr)

//@[typedef]
struct C.Tcl_Interp{}

fn C.Tcl_Init(interp &C.Tcl_Interp) int

fn C.Tcl_SetVar(&C.Tcl_Interp, &char, &char, int)

fn app_init(interp &C.Tcl_Interp) int {
	if C.Tcl_Init(interp) == C.TCL_ERROR {
		return C.TCL_ERROR
	}
	C.Tcl_SetVar(interp, c'tcl_rcFileName', c'~/.wishrc', C.TCL_GLOBAL_ONLY)

	return C.TCL_OK
}

fn main() {
	C.Tcl_Main(0, g_main_argv, app_init)
}

#pkgconfig is accepted BUT it doesn't work.

With tcc I got this:

$ v -show-c-output run tclsh.v
======== Output of the C Compiler (/home/jorge/v/thirdparty/tcc/tcc.exe) ========
/home/jorge/v/thirdparty/tcc/lib/libgc.a: error: 'GC_noop1_ptr' defined twice
=================================================================================
0x74ca7979d7fd: at ???: RUNTIME ERROR: invalid memory access

With gcc I got this:

$ v -cc gcc -show-c-output run tclsh.v
======== Output of the C Compiler (gcc) ========

================================================
signal 11: segmentation fault
                                                        | 0x7e9f1e242520 | /lib/x86_64-linux-gnu/libc.so.6(+0x42520) 
                                                        | 0x7e9f1e39d7fd | /lib/x86_64-linux-gnu/libc.so.6(+0x19d7fd) 
                                                        | 0x7e9f1e65012d | /lib/x86_64-linux-gnu/libtcl8.6.so(Tcl_ExternalToUtfDString+0x16d) 
                                                        | 0x7e9f1e697a96 | /lib/x86_64-linux-gnu/libtcl8.6.so(Tcl_MainEx+0x136) 
                                                        | 0x5a878e2242db | /home/jorge/gitlab.com/jmireles/viva/tcl/extending/tclsh(+0x2e2db) 
                                                        | 0x5a878e2244e0 | /home/jorge/gitlab.com/jmireles/viva/tcl/extending/tclsh(+0x2e4e0) 
                                                        | 0x7e9f1e229d90 | /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) 
                                                        | 0x7e9f1e229e40 | /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) 
                                                        | 0x5a878e1f9ed5 | /home/jorge/gitlab.com/jmireles/viva/tcl/extending/tclsh(+0x3ed5)

Help wanted.

@jorgeluismireles
Copy link

jorgeluismireles commented Dec 6, 2024

After some v up for other things, the code above worked. Even I run v -prod tcl_sh.v and generated a 175kb working app. So for me the pkgconfig issue works I assume after a fresh tcl dev installation in the default folders.

Also I think doing v wipe-cache directly or not, can solve some issues.

@jorgeluismireles
Copy link

For completeness here is a tk app with a script embed:

module main

#pkgconfig tcl
#pkgconfig tk

#include <tcl.h>
#include <tk.h>

@[typedef]
struct C.Tcl_Interp{}

fn C.Tk_MainEx(argc int, argv &&char, init voidptr, &C.Tcl_Interp)

fn C.Tcl_Init(interp &C.Tcl_Interp) int
fn C.Tk_Init(interp &C.Tcl_Interp) int
fn C.Tcl_Eval(interp &C.Tcl_Interp, script &char) int
fn C.Tcl_EvalFile(interp &C.Tcl_Interp, filename &char) int
fn C.Tcl_CreateInterp() &C.Tcl_Interp

fn app_init(interp &C.Tcl_Interp) int {

    if C.Tcl_Init(interp) == C.TCL_ERROR {
        return C.TCL_ERROR
    }
    if C.Tk_Init(interp) == C.TCL_ERROR {
        return C.TCL_ERROR
    }
    script := [
		'wm title . "Doodle in V"'
		''
		'proc doodle {w {color black}} {'
		'   bind \$w <1>         [list doodle\'start %W %x %y \$color]'
		'   bind \$w <B1-Motion> {doodle\'move %W %x %y}'
		'}'
		'proc doodle\'start {w x y color} {'
		'   set ::_id [\$w create line \$x \$y \$x \$y -fill \$color]'
		'}'
		'proc doodle\'move {w x y} {'
		'	\$w coords \$::_id [concat [\$w coords \$::_id] \$x \$y]'
		'}'
		'pack [canvas .c -bg white] -fill both -expand 1'
		'doodle       .c'
		'bind .c <Double-3> {%W delete all}'
	]
	lines := script.join('\n').str

    C.Tcl_Eval(interp, unsafe { &lines[0] })
    //C.Tcl_EvalFile(interp, c'doodle.tcl')
    return C.TCL_OK
}

fn main() {
	C.Tk_MainEx(g_main_argc, g_main_argv, app_init, C.Tcl_CreateInterp())
}

Screenshot from 2024-12-06 20-02-53
This is the TCL script which implements the drawing:

package require Tk
wm title . Draw

proc doodle {w {color black}} {
   bind $w <1>         [list doodle'start %W %x %y $color]
   bind $w <B1-Motion> {doodle'move %W %x %y}
}
proc doodle'start {w x y color} {
   set ::_id [$w create line $x $y $x $y -fill $color]
}
proc doodle'move {w x y} {
   $w coords $::_id [concat [$w coords $::_id] $x $y]
}
pack [canvas .c -bg white] -fill both -expand 1
doodle       .c
bind .c <Double-3> {%W delete all}

Yes, technology from the 90s.

@abc-JYL
Copy link
Author

abc-JYL commented Dec 9, 2024

Since I installed Linux on my mac so let me try, @jorgeluismireles you since pretty interest in tcl/tk, why not make a tcl/tk wrapper together?

@abc-JYL
Copy link
Author

abc-JYL commented Dec 9, 2024

I did work on linux maybe their is some env problem on macos

@abc-JYL abc-JYL closed this as completed Dec 9, 2024
@abc-JYL
Copy link
Author

abc-JYL commented Dec 9, 2024

Any way @jorgeluismireles I will create a new github repo you are welcome to contribute!

@jorgeluismireles
Copy link

Any way @jorgeluismireles I will create a new github repo you are welcome to contribute!

Thanks, you could open a discussion and in there share ideas and findings.

@abc-JYL
Copy link
Author

abc-JYL commented Dec 9, 2024

Any way @jorgeluismireles I will create a new github repo you are welcome to contribute!

Thanks, you could open a discussion and in there share ideas and findings.

Here is the github repo link: https://github.com/abc-JYL/tcl

@spytheman
Copy link
Member

spytheman commented Dec 10, 2024

Please try again with latest V. I've added more brew folders that are searched for .pc files.

#pkgconfig zlib and #pkgconfig tk, which depended on it, should work now on macos.

abc-JYL added a commit to abc-JYL/tcl that referenced this issue Dec 10, 2024
@abc-JYL
Copy link
Author

abc-JYL commented Dec 10, 2024

Fixed: export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig" to add zlib to pkg-config path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

3 participants