- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我构建代码时,我的 Code::Blocks IDE 仅调用“错误:ld 返回 1 退出状态”。我经常看到“collect2:”这个错误是“collect2: ld returned 1 exit status”。我只知道这是链接器错误。所以我需要包括另一个 linraries。
但我没有经验,即使是 C++ 也无法使用此 IDE。
所以我不明白如何摆脱这个错误。
我想请教以下问题。
1)如何摆脱这个错误。考虑了哪些问题。
2)如何设置构建选项以适合下面的代码。
注意(构建选项):添加链接器设置中的链接库
../../opencv-2.4.13/build/lib/libopencv_highgui.so
../../opencv-2.4.13/build/lib/libopencv_core.so
../../opencv-2.4.13/build/lib/libopencv_imgproc.so
pthread
boost_system
并且,搜索目录中的编译器是
../../opencv-2.4.13/include/opencv
../../../../usr/include/boost
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/managed_mapped_file.hpp>
#include <boost/interprocess/containers/vector.hpp> // boost/containers/vector.hpp
#include <boost/interprocess/containers/string.hpp> // boost/containers/string.hpp
#include <iostream>
#include <sys/time.h>
#include <stdio.h>
// void_allocator;
namespace bip = boost::interprocess;
typedef unsigned char uchar;
//Typedefs of allocators and containers
typedef bip::managed_shared_memory::segment_manager segment_manager_t;
typedef bip::allocator<void, segment_manager_t> void_allocator;
typedef void_allocator::rebind<uchar>::other uchar_allocator;
typedef bip::vector<uchar, uchar_allocator> uchar_vector;
template <typename Alloc = std::allocator<uchar> >
struct BasicInData {
public:
BasicInData(Alloc alloc = {}) : image(alloc)
{ }
template <typename T>
BasicInData(double x, int sizeImg, uchar_vector& image, Alloc alloc = {}) :
x(x), sizeImg(sizeImg), image(alloc)
{ }
double x = 0;
int sizeImg = 0;
uchar_vector image;
};
using InData = BasicInData<>; // just heap allocated
namespace Shared {
using segment = bip::managed_shared_memory;
using segment_manager = segment::segment_manager;
template <typename T> using alloc = bip::allocator<T, segment_manager>;
template <typename T> using vector = bip::vector<T, alloc<T> >;
using InData = BasicInData<alloc<uchar> >; // shared memory version
vector<InData>& locate(segment& smt) {
auto* v = smt.find_or_construct<vector<InData> >("InDataVector")(smt.get_segment_manager());
assert(v);
return *v;
}
}
int main(int argc, char* argv[]) {
if(argc == 1){ //Parent process
// Remove shared memory on construction and destruction
// Create a new segment with given name and size
struct timeval tv;
gettimeofday(&tv, NULL);
struct shm_remove
{
shm_remove(){bip::shared_memory_object::remove("MySharedMemory");}
~shm_remove(){bip::shared_memory_object::remove("MySharedMemory");}
}remover;
Shared::segment smt(bip::create_only,"MySharedMemory", 65536); // 10 Kb for coliru
auto &data = Shared::locate(smt);
//Shared::alloc bip::alloc_inst (data);
cv::Mat_<cv::Vec3b> mat;
cv::VideoCapture vcap(0);
Shared::InData id(smt.get_segment_manager());
if (!vcap.isOpened())
return -1;
while (1) {
vcap >> mat;
int image_size = mat.total() * mat.elemSize();
id.sizeImg = image_size;
id.image.resize(image_size * sizeof(uchar));
memcpy(&id.image[0], mat.data, image_size * sizeof(uchar));
//Launch child process
gettimeofday(&tv, NULL);
double time = ((double)tv.tv_usec/1000000);
id.x = time;
data.push_back(id);
if(cv::waitKey(30) >= 0) break;
}
std::string s(argv[0]); s += " child";
if(0 != std::system(s.c_str()))
return 1;
// check child has destroyed the vector
if(smt.find<Shared::vector<InData>>("InDataVector").first)
return 1;
} else{
// Open the managed segment
bip::managed_shared_memory segment(bip::open_only, "MySharedMemory");
// Find the vector using c-string name
bip::vector<InData> *myvector = segment.find<bip::vector<InData>>("InDataVector").first;
// Use vector in reverse order
bip::vector<InData>::iterator it;
cv::Mat_<cv::Vec3b> im;
for(it = myvector->begin(); it !=myvector->end(); ++it){
im.resize(it->sizeImg);
memcpy(im.data, &it->image[0], it->sizeImg);
cv::imshow("window1", im);
}
segment.destroy<bip::vector<InData>>("InDataVector");
return 0;
}
}
最佳答案
谢谢,@greatwolf。最后,我可以摆脱那个错误。现在,我在下面显示“链接器设置”。
../../opencv-2.4.13/build/lib/libopencv_highgui.so
../../opencv-2.4.13/build/lib/libopencv_core.so
../../opencv-2.4.13/build/lib/libopencv_imgproc.so
pthread
boost_system
rt
关于c++ - 代码:: block 输出 "error: ld returned 1 exit status"没有其他,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455552/
询问 unrelated question我有这样的代码: public boolean equals(Object obj) { if (this == obj) retur
在我之前的一个问题中 js: Multiple return in Ternary Operator我询问了有关使用三元运算符返回多个参数的问题。但是现在参数IsActveUser boolean(t
假设我有一个带有 return 的 if 语句。从效率的角度来看,我应该使用 if(A > B): return A+1 return A-1 或 if(A > B): return
例如考虑以下代码: int main(int argc,char *argv[]) { int *p,*q; p = (int *)malloc(sizeof(int)*10); q
PyCharm 对这段代码发出警告,说最后一个返回是不可访问的: def foo(): with open(...): return 1 return 0 如果 ope
我想实现这样的目标: 如果在返回 Json 的方法中抛出异常,则返回 new Json(new { success = false, error = "unknown"}); 但如果方法返回 View
它是多余的,但我正在学习 JS,我想知道它是如何工作的。 直接从模块返回函数 let func1 = function () { let test = function () {
我不明白我应该使用什么。我有两页 - intro.jsp(1) 和 booksList.jsp(2)。我为每一页创建了一个 Controller 类。第一页有打开第二页的按钮:
我最近在 Joomla 组件(Kunena,更准确地说是 Kunena)中看到这段代码,那么使用 $this->return VS 简单的 return 语句有什么区别. 我已经用谷歌搜索了代码,但没
我的类实现了 IEnumerable。并且可以编译这两种方式来编写 GetEnumerator 方法: public IEnumerator GetEnumerator() { yield r
我只是在编码,我想到了一个简单的想法(显然是问题),如果我有一个像这样的函数: int fun1(int p){ return(p); } 我有一个这样的函数: int fun1(int p){
这个问题在这里已经有了答案: What does the comma operator do in JavaScript? (5 个答案) 关闭 9 年前。 function makeArray
假设我写了一个 for 循环,它将输出所有数字 1 到 x: x=4 for number in xrange(1,x+1): print number, #Output: 1 2 3 4 现
我最近在这个 Apache Axis tutorial example. 中看到了下面的一段代码 int main() { int status = AXIS2_SUCCESS; ax
function a(){ return{ bb:"a" } } and function a(){ return { bb:"a" } } 这两个代码有什么区别吗,如果有请
function a() { return 1; } function b() { return(1); } 我在 Chrome 的控制台中测试了上面的代码,都返回了 1。 function c()
考虑这三个函数: def my_func1(): print "Hello World" return None def my_func2(): print "Hello World"
这可能是一个愚蠢的问题,但我正在努力,如果有一种简明的方法来测试函数的返回结果,如果它不满足条件,则返回该值(即,传递它)。。现在来回答一个可能的问题,是的,我正在寻找的类似于例外提供的东西。然而,作
我正在测试一个函数,并尝试使用 return 来做什么,并在 PowerShell 5.1 和 PwSh 7.1 中偶然发现了一个奇怪的问题,即 return cmdlet似乎不适合在团体中工作: P
这个问题已经有答案了: Return in generator together with yield (2 个回答) Why can't I use yield with return? (5 个回
我是一名优秀的程序员,十分优秀!