我有点困惑,因为我们应该在objective-c中使用FOUNDATION_EXPORT,它的目的是什么?任何人都可以用外行来解释一下吗?谢谢!
这是我的问题:
谁能帮我?谢谢...
编辑:这里有一些未定义的参考消息:
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_guess_format'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_read_frame'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_write_header'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_interleaved_write_frame'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_find_stream_info'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_register_all'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_init_packet'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_alloc_context'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_dump_format'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avio_close'
Run Code Online (Sandbox Code Playgroud)
edit2:这是"构建失败"后得到的消息:
-> task in 'scratch-simulator' failed (exit status 1):
{task …Run Code Online (Sandbox Code Playgroud) 以下C++代码使用Visual C++和g ++编译:
struct S
{
static void foo();
};
extern "C"
void S::foo() {}
struct T
{
static void foo();
};
extern "C"
void T::foo() {}
auto main() -> int
{
S().foo();
T().foo();
}
Run Code Online (Sandbox Code Playgroud)
有效吗?
如果它是有效的,因为实现可能在一个单独的转换单元中,这是否意味着静态成员函数总是具有与C函数相同的调用约定(如果不是,它如何不暗示)?
我extern "C" int ping(void)在C++"静态库"项目中有一个函数.现在,我想写一个简单的Hello-World C程序来调用这个函数int x = ping();.
我使用,g++ / gcc但我无法将C可执行文件与C++共享库链接.拜托,怎么能这样做?你能提供准确的gcc命令吗?
编辑:
g++ -c -static liba.cpp
ar rcs liba.a liba.o
gcc -o x main.o -L. -la
Run Code Online (Sandbox Code Playgroud)
得到:
./liba.a(liba.o):(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
Run Code Online (Sandbox Code Playgroud)
collect2:ld返回1退出状态
环境是Windows,MS Visual Studio 2012.如何在C(而不是C++)应用程序中使用我用C++编写的DLL库?在我的DLL中,我使用了名称空间,类等.例如,我写了两个简单的项目:
两者都是用C++编写的.任何人都可以向我展示一个用C编写的类似应用程序,它使用C++库吗?
谢谢.
\n\n\n由于一些建议而更新
\n
系统\xef\xbc\x9amacOS 10.14.6
\n\n这里我想问的问题是如何使用rust调用编译好的.so文件,抱歉,我对这部分是新手。
\n\n我有一个非常简单的 c 文件:
\n\n#include "add.h"\n\nint add(int a, int b) {\n return a + b;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n然后我习惯gcc-fPIC -shared -o libadd.so add.c编译成.so文件放到lib目录下
然后我在 rust 的 build.rs 文件中写入了以下内容:
\n\n\nuse std::env;\nuse std::path::{Path};\n\nfn main() {\n let pwd_dir = env::var("CARGO_MANIFEST_DIR").unwrap();\n let path = Path::new(&*pwd_dir).join("lib");\n println!("cargo:rustc-link-search=native={}", path.to_str().unwrap());\n println!("cargo:rustc-link-lib=dylib=add");\n // println!("cargo:rustc-link-lib=static=add");\n // println!("cargo:rerun-if-changed=src/hello.c");\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我希望我可以得到并使用这个函数,main.rs 是:
\n\nextern { fn add(a: i32, b: i32) -> i32; }\n\nfn main() {\n let c = unsafe …Run Code Online (Sandbox Code Playgroud) 我正在尝试做类似以下的事情
enum types {None, Bool, Short, Char, Integer, Double, Long, Ptr};
int main(int argc, char ** args) {
enum types params[10] = {0};
void* triangle = dlopen("./foo.so", RTLD_LAZY);
void * fun = dlsym(triangle, ars[1]);
<<pseudo code>>
}
Run Code Online (Sandbox Code Playgroud)
伪代码就像
fun = {}
for param in params:
if param == None:
fun += void
if param == Bool:
fun += Boolean
if param == Integer:
fun += int
...
returnVal = fun.pop()
funSignature = returnval + " " + funName + "(" …Run Code Online (Sandbox Code Playgroud) 我问这个是因为我正在编写一个使用C库的C++程序.该库具有foreach回调(自然)的功能.显然,库会将我的回调称为C函数.
首先,这与C与C++的链接有什么关系?
如果确实如此,这样的有效和正确吗?
extern "C" static bool callback(/*parameters*/)
{
cout << "C++ thing inside the function" << endl;
/* etc */
}
Run Code Online (Sandbox Code Playgroud) 我想在C中实现一个项目,但是用C++编写项目的某些部分然后从主C代码中调用它们很方便.
可能吗?!如果是的话,我怎么能这样做?!
提前致谢 :)
PS
我在我的 C++代码中使用了一些库,比如 OpenCV.
我有外部.DLL文件,里面有快速汇编程序代码.调用此.DLL文件中的函数以获得最佳性能的最佳方法是什么?