我正在尝试按照 http://snowsyn.net/2016/09/11/creating-shared-libraries-in-go/ 中的说明进行操作
我的项目比较简单。该库有一个带有 println 的测试函数。正如标题所说,我越来越“找不到”。
我正在运行 Ubuntu zesty 并升级到 1.7.4
ls -l
roy@roy-desktop:~/go/src/c$ ls -l
2016年合计
-rw-rw-r-- 1 roy roy 43 Dec 10 06:55 test.c
-rw-rw-r-- 1 roy roy 1274 Dec 10 06:54 test.h
-rw-rw-r-- 1 roy roy 2053664 Dec 10 06:54 test.so
测试.c
#include "test.h"
int main() {
test();
}
lib.go
package main
import "fmt"
import "C"
//export test
func test() {
fmt.Println("test")
}
func main() {}
test.h 和 test.so 是通过以下方式生成的:go build -o test.so -buildmode=c-shared test.go
调用 gcc 失败如下:
roy@roy-desktop:~/go/src/c$ gcc -o test test.c -L. -ltest
/usr/bin/ld: cannot find -ltest
collect2: error: ld returned 1 exit status
原始示例使用 clang,但谷歌搜索表明该调用也适用于 gcc。
一些额外的评论:
go func test() {} 中的函数名称将在 nm 中显示为 _test 但应在 C 中声明为 extern void test ();
出于某种原因,调用 go build -buildmode=c-shared 不会在 OSX 上生成头文件,但会在 Linux 上生成。
最佳答案
注意你说的指令中go build命令行的区别 您正在关注:
go build -o libimgutil.so -buildmode=c-shared imgutil.go
+++^^^^^^^^^^ ^^^^^^^^^^
和你自己的 go build 命令:
go build -o test.so -buildmode=c-shared test.go
^^^^^^^ ^^^^^^^
根据 the documentation of the linker
option -l | --library 考虑这种差异
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link.
^^^^^^^^
This option may be used any number of times. If namespec is of the form :filename,
^^^^^^^^ +^^^^^^^^
ld will search the library path for a file called filename, otherwise it will
^^^^^^^^
search the library path for a file called libnamespec.a.
+++^^^^^^^^++
On ... ELF and SunOS systems, ld will search a directory for a library called
libnamespec.so before searching for one called libnamespec.a. (By convention,
+++^^^^^^^^+++ +++^^^^^^^^++
a .so extension indicates a shared library.) ...
这将向您展示您的 go build 命令需要:
go build -o libtest.so -buildmode=c-shared test.go
关于gcc - Linux 上的 Golang c-shared - ld 找不到 -ltest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47736729/
这似乎应该有一个直截了当的答案,但在Google上花了很多时间,所以我找不到它。这可能是缺少正确关键字的情况。在我的RoR应用程序中,我有几个模型共享一种特定类型的字符串属性,该属性具有特殊验证和其他功能。我能想到的最接近的类似示例是表示URL的字符串。这会导致模型中出现大量重复(甚至单元测试中会出现更多重复),但我不确定如何让它更DRY。我能想到几个可能的方向...按照“validates_url_format_of”插件,但这只会让验证干给这个特殊的字符串它自己的模型,但这看起来很像重溶液为这个特殊的字符串创建一个ruby类,但是我如何得到ActiveRecord关联这个类模型
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在使用RubyonRails3.2.2,我想从我的模型/类中“提取”一些方法。也就是说,在不止一个类/模型中,我有一些方法(注意:方法与用户授权相关,并被命名为“CRUD方式”),这些方法实际上是相同的;所以我认为DRY方法是将这些方法放在“共享”模块或类似的东西中。实现该目标的常见且正确的方法是什么?例如,我应该将“共享”代码放在哪里(在哪些目录和文件中)?如何在我的类/模型中包含提到的方法?你有什么建议?注意:我正在寻找“RubyonRails制作东西的方式”。 最佳答案 一种流行的方法是使用ActiveSupport关注点
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
我有一个.pfx格式的证书,我需要使用ruby提取公共(public)、私有(private)和CA证书。使用shell我可以这样做:#ExtractPublicKey(askforpassword)opensslpkcs12-infile.pfx-outfile_public.pem-clcerts-nokeys#ExtractCertificateAuthorityKey(askforpassword)opensslpkcs12-infile.pfx-outfile_ca.pem-cacerts-nokeys#ExtractPrivateKey(askforpassword)o
我已经看到了一些其他的问题,尝试了他们的建议,但没有一个对我有用。我已经使用Rails大约一年了,刚刚开始一个新的Rails项目,突然遇到了问题。我卸载并尝试重新安装所有Ruby和Rails。Ruby很好,但Rails不行。当我输入railss时,我得到了can'tfindgemrailties。我当前的Ruby版本是ruby2.2.2p95(2015-04-13修订版50295)[x86_64-darwin15],尽管我一直在尝试通过rbenv设置ruby2.3.0。如果我尝试rails-v查看我正在运行的版本,我会得到同样的错误。我使用的是MacOSXElCapitan版本10
我花了几天时间尝试安装ruby1.9.2并让它与gems一起工作:-/我最终放弃了我的MacOSX10.6机器,下面是我的Ubuntu机器上的当前状态。任何建议将不胜感激!#rubytest.rb:29:in`require':nosuchfiletoload--mongo(LoadError)from:29:in`require'fromtest.rb:1:in`'#cattest.rbrequire'mongo'db=Mongo::Connection.new.db("mydb")#gemwhichmongo/usr/local/rvm/gems/ruby-1.9.2-p0/g