N
N
nakem2022-01-17 07:03:06
go
nakem, 2022-01-17 07:03:06

How to add c++ sources to golang library?

The project used cgo c++ sources. I decided to put some code base into a separate package, SPP resources also went there. How to add a new package to a project?
Here is the package structure.

cpp_sources                       pkg                               
      opus                       audio
cpp and hpp files               go files


Here is the c++ assembly in the package.
/*
#cgo linux CFLAGS: -I${SRCDIR}/../../cpp_source/opus -I/usr/include/opus
#cgo linux CPPFLAGS: -I${SRCDIR}/../../cpp_source/opus -I/usr/include/opus
#cgo linux LDFLAGS: -L${SRCDIR} -lopus_decoder_wrapper -lopus -lopusenc -lopusfile -lstdc++
#cgo darwin CFLAGS: -I${SRCDIR}/../../cpp_source/opus -I/usr/local/include/opus
#cgo darwin CPPFLAGS: -I${SRCDIR}/../../cpp_source/opus -I/usr/local/include/opus
#cgo darwin LDFLAGS: -L${SRCDIR} -lopus_decoder_wrapper -lopus -lopusenc -lopusfile -lc++
#include <opus_decoder_wrapper.h>
*/
import "C"


I'm only importing the audio directory into the project now. But I understand that you first need to build the package or import it somehow with SPP resources or do something else. I need to vendor the project.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
khevse, 2022-01-18
@khevse

Once upon a time I did something similar, but under windows. The example does not seem complicated, I think that you will be able to figure it out.
Link to github

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question