raysan5 / rres

A simple and easy-to-use file-format to package resources
MIT License
391 stars 34 forks source link

collect2: error: ld returned 1 exit status #19

Closed JupiterRider closed 1 year ago

JupiterRider commented 1 year ago

Hey @raysan5,

I am trying to work on a golang binding for rres, but I experience linker errors.

Here is a small example:

package main

// #include <rres.h>
// #include <stdlib.h>
import "C"
import "unsafe"

func main() {
    cfileName := C.CString("data.rres")
    defer C.free(unsafe.Pointer(cfileName))
    C.rresLoadCentralDirectory(cfileName)
}

This is the folder structure:

.
├── external
│   ├── aes.c
│   ├── aes.h
│   ├── lz4.c
│   ├── lz4.h
│   ├── monocypher.c
│   ├── monocypher.h
│   └── qoi.h
├── go.mod
├── main.go
├── rres.h
└── rres-raylib.h

This is the error:

/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-795614298/000001.o: in function `_cgo_cfce9f3b0a11_Cfunc_rresLoadCentralDirectory':
/tmp/go-build/main.cgo2.c:64: undefined reference to `rresLoadCentralDirectory'
collect2: error: ld returned 1 exit status

Thanks in advance!

raysan5 commented 1 year ago

@JupiterRider Not sure how Go works exactly but it seems you are not including the rres library... did you check the C usage examples?

JupiterRider commented 1 year ago

@raysan5 Yeah, with these includes and defines from the examples, it works now:

#include <raylib.h>
#define RRES_IMPLEMENTATION
#include <rres.h>
#define RRES_RAYLIB_IMPLEMENTATION
#define RRES_SUPPORT_COMPRESSION_LZ4
#define RRES_SUPPORT_ENCRYPTION_AES
#define RRES_SUPPORT_ENCRYPTION_XCHACHA20
#include <rres-raylib.h>

Thanks!