Is it possible to interpose exported functions.

88 views
Skip to first unread message

eme...@gmail.com

unread,
Aug 7, 2020, 1:13:53 AM8/7/20
to golang-nuts
Here in the example below:
package main

import (
"C"
"fmt"
)

//export test
func test() {
fmt.Println("test code")
}

func main() {

}

The above package was built using -builtmode=c-shared. I wanted to load the built library in my C code, and interpose the esported function 'test'. I wonder if this is possible at all.

Thanks:)

Lutz Horn

unread,
Aug 7, 2020, 2:47:38 AM8/7/20
to golan...@googlegroups.com
Am 07.08.20 um 05:00 schrieb eme...@gmail.com:
> //export test
> func test() {
> fmt.Println("test code")
> }

`test` is not exported. It would be, if it was called `Test` with a
capital `T`.

Lutz

Yonatan Gizachew

unread,
Aug 7, 2020, 3:05:59 AM8/7/20
to golang-nuts
Okay, thanks for that. What about now?


package main

import (
"C"
"fmt"
)

//export Test
func Test() {

fmt.Println("test code")
}

func main() {

}

Lutz Horn

unread,
Aug 7, 2020, 3:25:06 AM8/7/20
to golan...@googlegroups.com
Am 07.08.20 um 09:05 schrieb Yonatan Gizachew:
> //export Test
> func Test() {
> fmt.Println("test code")
> }

Yes, now `Test` is exported.

Lutz
Message has been deleted

Yonatan Gizachew

unread,
Aug 7, 2020, 3:47:26 AM8/7/20
to golang-nuts
Yeah, but my question is if it is possible to interpose the exported function

Ian Lance Taylor

unread,
Aug 7, 2020, 12:37:40 PM8/7/20
to Yonatan Gizachew, golang-nuts
On Fri, Aug 7, 2020 at 12:47 AM Yonatan Gizachew <eme...@gmail.com> wrote:
>
> Yeah, but my question is if it is possible to interpose the exported function

Yes, it should be possible.

Ian



> On Friday, August 7, 2020 at 4:25:06 PM UTC+9 Lutz Horn wrote:
>>
>> Am 07.08.20 um 09:05 schrieb Yonatan Gizachew:
>> > //export Test
>> > func Test() {
>> > fmt.Println("test code")
>> > }
>>
>> Yes, now `Test` is exported.
>>
>> Lutz
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/27887bbd-d3f4-4205-8bc7-303c17087d47n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages