-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cgo: Nowhere to specify C/C++ source files #12953
Comments
The Am I right in interpreting your request? Do you want the |
@adg If golang can't do such thing, I have to build the c part manually, maybe something like:
instead of:
Python has the ability to do such work, so I wish golang can also do. |
Executing arbitrary code is something the You could use a |
The purpose of the PR is not to Executing arbitrary code but to make it configurable for cgo to work on any source tree. It will also be no painful for users using the library, they don't need to care about the compilation any more. If they want to use the pkg, just go install like all other pkgs. Please consider again. |
I believe that if you follow this goal through to its logical conclusion then you end up with arbitrary code execution. Please correct me if I'm wrong. |
Go is not a build system. Check out http://bazel.io/ |
@adg Would you please explain the details? I don't think this will bring any extra security issues(arbitrary code execution). Given the feature, all C/C++ source files are specified by Peter who write the golang code. If he want to execute any evil C++ code in the go project, he can do it without the proposed feature. One concern is: Peter should not add files outside the project ( @bradfitz That's true, python is not a build system neither. In my view, go is to python as cgo is to cython. Cython can do such stuff while cgo can't. Go is not a build system but actually it(cgo) does, though not doing very tell. Why not trying to make it better. Libmc, As a open-source library (not a standlone program), I wish there's no pain for users to use it. Peter can install the library |
go build is designed to build Go packages, not C/C++ libraries.
If a Go package happens to use cgo, go build will build the C/C++/Obj-C
source code in the same directory as the Go package (this is necessary
because not all cgo code can be put in the cgo preamble in Go source
files.)
However, go build will not attempt to build arbitrary C/C++ source code
outside the Go package it's building.
|
Ideally, I don't think C/C++ source code should be treated as part of a go pkg, but the library built using source files is. Different C project has different source tree. You can't demand all existed C* library to be organised the way golang like: Put all source file in a single directory , not even a sub-directory! |
Different C/C++ library have different build procedures, for example,
some require running a configure script before make, should go build
support building those?
The C/C++ library that the Go package interfaces with should be built
separately.
|
should go build support building those? You can build libmc using cmake, that does not mean you have to use cmake. You can even use autotools to to build it if you like. These are just build tools. c go is also shipped with a build tool, and the point is, the build tool is not working well.
ANSWER is in : #12953 (comment) , in addition: That's true and is the common case. In such way, I have to release the C++ part as a separate library, and resolve version problems between the Python/Golang wrapper and the base library. If the base library is upgraded, programs running under the old version of the Python/Golang wrapper may break. That's terrible. Now that I can build source files from the scratch in Python and Golang, why not? |
Use a Makefile that runs "go build". |
Or add a go generate rule that create stub C files
that simply include the actual files.
|
What version of Go are you using (go version)?
go version go1.5 darwin/amd64
What operating system and processor architecture are you using?
Darwin PANs-MacBook-Pro.local 15.0.0 Darwin Kernel Version 15.0.0: Wed Aug 26 16:57:32 PDT 2015; root:xnu-3247.1.106~1/RELEASE_X86_64 x86_64
What did you do?
Support there's a go project based on cgo. Both of the C/C++ code are in the same repo. All c header files are listed in the
include
directory and c source files listed in thesrc
directory. An ideal way to place the golang code is put it in agolibmc
directory:What did you expect to see?
I expected there was a directive (e.g.:
#cgo SOURCES ../src/*.c ../src/hashkit/*.c
) for me to specify all C/C++ source files need to be compiled. But cgo can only find source files in the same directory where the .go file exists.What did you see instead?
I cannot find the expected directive mentioned in 4, then I have to re-organize the source tree in a smelly way:
An example in the wild world is http://github.com/douban/libmc
The text was updated successfully, but these errors were encountered: