I’m trying to build an open source c++ library with gcc and eclipse.
But I get this error
‘memcpy’ was not declared in this scope
I’ve try to include memory.h (and string.h) and eclipse find the function if I click «open declaration» but gcc give me the error.
How can I do?
#include <algorithm>
#include <memory.h>
namespace rosic
{
//etc etc
template <class T>
void circularShift(T *buffer, int length, int numPositions)
{
int na = abs(numPositions);
while( na > length )
na -=length;
T *tmp = new T[na];
if( numPositions < 0 )
{
memcpy( tmp, buffer, na*sizeof(T));
memmove( buffer, &buffer[na], (length-na)*sizeof(T));
memcpy( &buffer[length-na], tmp, na*sizeof(T));
}
else if( numPositions > 0 )
{
memcpy( tmp, &buffer[length-na], na*sizeof(T));
memmove(&buffer[na], buffer, (length-na)*sizeof(T));
memcpy( buffer, tmp, na*sizeof(T));
}
delete[] tmp;
}
//etc etc
}
I get error on each memcpy and memmove function.
Please state the information for your system
- OpenCV version: 3.0/3.1/master
- Host OS: Linux (Ubuntu 16.04)
- Compiler: GCC 4.7/4.8/4.9/5.0
- CUDA 7.5 (from synaptic package manager («nvidia-cuda-toolkit»))
In which part of the OpenCV library you got the issue?
- cuda
When trying to compile opencv (ubuntu 16.04) i get the following error:
[ 9%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
/usr/include/string.h: In function ‘void* mempcpy_inline(void, const void, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;
^
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:264 (message):
Error generating file
/home/mag/opencv/build_opencv_master/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
The problem is known, but you need to make a workaround to support cuda. Here is a link to the same Proplem in the caffe git, but unfortunetly the solution doesnt work for me:
BVLC/caffe#4046
- Forum
- UNIX/Linux Programming
- compiling c++ programs in ubuntu g++
compiling c++ programs in ubuntu g++
hi every one i am new to c++ programming. i got an error as shown below
«root@ubuntu:/home/ramreddy/Desktop/tts/speech_tools# make
Making in directory ./siod …
gcc -c -fno-implicit-templates -O3 -Wall -DSUPPORT_EDITLINE -I../include slib.cc
In file included from ../include/EST_String.h:50:0,
from ../include/siod.h:17,
from slib.cc:88:
../include/EST_iostream.h:53:25: fatal error: iostream.h: No such file or directory
compilation terminated.»
please help me is there any lib file is missing or any other
thanks in advance
Working as root?
iostream.h is deprecated. It’s part of the old I/O Stream library and was replaced by the C++98 standard.
The replacement is
hi,
thanks for the response. initially i got an error as
../../include/../base_class/EST_TSimpleMatrix.cc:54:5: error: ‘memcpy’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from /usr/include/string.h:642:0,
from /usr/include/c++/4.7/cstring:44,
from ../../include/EST_String.h:42,
from ../../include/EST_error.h:182,
from ../../include/../base_class/EST_TMatrix.cc:48,
from matrix_i_t.cc:50:
/usr/include/i386-linux-gnu/bits/string3.h:49:1: note: ‘void* memcpy(void*, const void*, size_t)’ declared here, later in the translation unit
make[2]: *** [matrix_i_t.o] Error 1
make[1]: *** [inst_tmpl] Error 2
make: *** [base_class] Error 2
please help me
thanks.
Include <cstring> before using memcpy.
thank you it worked
Topic archived. No new replies allowed.
- Печать
Страницы: [1] Вниз
Тема: Проблемы при сборке, помогите решить (Прочитано 3249 раз)
0 Пользователей и 1 Гость просматривают эту тему.
Costa
День добрый!
Собираю тут одну программку и никак не могу взять в толк, где грабли.
Под виндой в Dev-C++ 4.9.9.2 собирается без проблем вот так:
g++ -c AES.cpp -o AES.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
Под Убунтой, собирая вот так (так у приятеля без проблем собирается, правда на другом дистре):
g++ -c AES.cpp -o AES.o
получаю такие грабли:
In file included from DataBuffer.h:27,
from AES.h:21,
from AES.cpp:18:
ByteString.h: In static member function ‘static int std::char_traits::compare(const unsigned char*, const unsigned char*, size_t)’:
ByteString.h:35: error: ‘memcmp’ was not declared in this scope
ByteString.h: In static member function ‘static unsigned char* std::char_traits::copy(unsigned char*, const unsigned char*, size_t)’:
ByteString.h:39: error: ‘memcpy’ was not declared in this scope
ByteString.h: In static member function ‘static unsigned char* std::char_traits::move(unsigned char*, const unsigned char*, size_t)’:
ByteString.h:43: error: ‘memmove’ was not declared in this scope
ByteString.h: In static member function ‘static unsigned char* std::char_traits::assign(unsigned char*, size_t, char)’:
ByteString.h:47: error: ‘memset’ was not declared in this scope
ByteString.h: In static member function ‘static const unsigned char* std::char_traits::find(const unsigned char*, size_t, const char&)’:
ByteString.h:51: error: ‘memchr’ was not declared in this scope
ByteString.h: In static member function ‘static int std::char_traits::eof()’:
ByteString.h:55: error: ‘EOF’ was not declared in this scope
ByteString.h: In static member function ‘static int std::char_traits::not_eof(const int&)’:
ByteString.h:67: error: ‘EOF’ was not declared in this scope
Чего же ему надо? Может надо какой пакет доставить или вручную пути к инклудам прописать? Посоветуйте.
ByteString.h
Чуть более подробные исходники — во вложении.
Mam(O)n
Не хватает
#include <cstring>
#include <cstdio>
Costa
Mam(O)n, спасибо, помогло!
Правда, повылезали warnings, почти все поубирал, но осталось пара настырных.
Вот здесь (фрагмент исходников) первая строчка выдает
warning: deprecated conversion from string constant to ‘char*’
char *keyString = "KEYx";
keyString[3] = i - 1 + '1';
И то же самое предупреждение во второй строчке:
DataBuffer var;
DataBuffer во вложении.
var = "bla-bla-bla";
Как это исправить?
wl
По новым правилам GCC строка должна быть const.
http://www.daniweb.com/forums/thread156711.html
int main(void) {
char *keyString1 = "KEYx";
char keyString2[] = "KEYx";
const char *keyString3 = "KEYx";
return 0;
}
$ g++ string_constant.c
string_constant.c: In function ‘int main()’:
string_constant.c:2: warning: deprecated conversion from string constant to ‘char*’
Т.е. на первую строку выдается предупреджение, на остальные — нет. У g++ есть ключ для отключения этого предупреждения.
« Последнее редактирование: 13 Января 2010, 12:27:43 от wl »
На свете феньки есть такие, брат Горацио, которых лохи просто не секут. (Шекспир, «Гамлет», вольный перевод)
Costa
Сделал так:
char keyString[] = "KEYx";
проходит.
А второе как поправить? Отключать предупреждения не хотелось бы, мало ли потом какие баги попрут.
wl
Недосуг мне скачивать архив, распаковывать его и лазить по тексту.
Если тип DataBuffer объявлен как-нибудь наподобие char * или char[ ], то вообще-то надо бы использовать strdup или strcpy.
Если это string, тогда можно написать string(«blah-blah-blah»);
На будущее рекомендую пользоваться spoiler-ами здесь или http://pastebin.com
На свете феньки есть такие, брат Горацио, которых лохи просто не секут. (Шекспир, «Гамлет», вольный перевод)
alexander.pronin
А второе как поправить? Отключать предупреждения не хотелось бы, мало ли потом какие баги попрут.
В классе DataBuffer у Вас такие конструкторы.
DataBuffer();
DataBuffer(const DataBuffer& buffer);
DataBuffer(const char *hexString);
DataBuffer(const char *hexString, size_t length);
DataBuffer(const unsigned char *data, size_t length);
DataBuffer(size_t size, unsigned char fill = 0);
Какой соответствует Вашему объявлению ?
wl
А оператора = перегруженного там нет?
На свете феньки есть такие, брат Горацио, которых лохи просто не секут. (Шекспир, «Гамлет», вольный перевод)
Costa
Кстати, есть:
DataBuffer& operator =(const DataBuffer& buffer);
DataBuffer& operator =(char *rvalue);
DataBuffer& operator =(const ByteString& string);
//=============================================================================
// Assignment operator for rvalue of type DataBuffer
DataBuffer& DataBuffer::operator = (const DataBuffer& buffer)
{
deleteHexString();
ByteString::operator=(buffer);
return *this;
}
//=============================================================================
// Assignment operator for rvalue of type char * (that is, string)
DataBuffer& DataBuffer::operator = (char *rvalue)
{
parse(rvalue, strlen(rvalue));
return *this;
}
//=============================================================================
// Assignment operator for rvalue of type ByteString
DataBuffer& DataBuffer::operator = (const ByteString& string)
{
ByteString::operator =(string);
return *this;
}
Спасибо за наводку, сейчас попробую сам дотумкать! В C++ я не очень мастак, в основном C, а код изначально написан Атмелом.
Пользователь решил продолжить мысль 13 Января 2010, 13:17:36:
Все сделал, огромное все спасибо!
DataBuffer& operator =(char const *rvalue);
//=============================================================================
// Assignment operator for rvalue of type char * (that is, string)
DataBuffer& DataBuffer::operator = (char const *rvalue)
{
parse(rvalue, strlen(rvalue));
return *this;
}
« Последнее редактирование: 13 Января 2010, 13:17:36 от Costa »
- Печать
Страницы: [1] Вверх
View previous topic :: View next topic | |||||||||||
Author | Message | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
audiodef Watchman Joined: 06 Jul 2005 |
|
||||||||||
Back to top |
|
||||||||||
VoidMage Watchman Joined: 14 Oct 2006 |
|
||||||||||
Back to top |
|
||||||||||
Hu Moderator Joined: 06 Mar 2007 |
|
||||||||||
Back to top |
|
||||||||||
audiodef Watchman Joined: 06 Jul 2005 |
|
||||||||||
Back to top |
|
||||||||||
Hu Moderator Joined: 06 Mar 2007 |
|
||||||||||
Back to top |
|
||||||||||
VoidMage Watchman Joined: 14 Oct 2006 |
|
||||||||||
Back to top |
|
||||||||||
|
You cannot post new topics in this forum |
Ubuntu Linux 16.04 LTS with GEForce GTX-950 GPU X86_64
Trying to build OpenCV on Ubuntu 16.04, make fails with an error compiling cuda file:
**[ 16%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;
^
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message):
Error generating file
/home/johann/Downloads/opencv-3.1.0/release/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
modules/core/CMakeFiles/opencv_core.dir/build.make:63: recipe for target** 'modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o' failed
make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o] Error 1
CMakeFiles/Makefile2:1722: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
Below is the output from the CMAKE configuration step:
[email protected]:~/Downloads/opencv-3.1.0/release$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
-- Detected version of GNU GCC: 54 (504)
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.8", minimum required is "1.2.3")
-- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
-- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR)
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8")
-- Checking for module 'gstreamer-base-1.0'
-- No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-video-1.0'
-- No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-app-1.0'
-- No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
-- No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
-- No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'gstreamer-base-0.10'
-- No package 'gstreamer-base-0.10' found
-- Checking for module 'gstreamer-video-0.10'
-- No package 'gstreamer-video-0.10' found
-- Checking for module 'gstreamer-app-0.10'
-- No package 'gstreamer-app-0.10' found
-- Checking for module 'gstreamer-riff-0.10'
-- No package 'gstreamer-riff-0.10' found
-- Checking for module 'gstreamer-pbutils-0.10'
-- No package 'gstreamer-pbutils-0.10' found
-- Checking for module 'libdc1394-2'
-- No package 'libdc1394-2' found
-- Checking for module 'libdc1394'
-- No package 'libdc1394' found
-- Checking for module 'libv4l1'
-- No package 'libv4l1' found
-- Checking for module 'libv4l2'
-- No package 'libv4l2' found
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Checking for module 'libavresample'
-- No package 'libavresample' found
-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found
-- Checking for module 'libgphoto2'
-- No package 'libgphoto2' found
-- found IPP (ICV version): 9.0.1 [9.0.1]
-- at: /home/johann/Downloads/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx
-- CUDA detected: 7.5
-- CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode ...
(more)
Actually I get this error if I try to build all CUDA architectures. Instead I just change 2 CMAKE variables, CUDA_ARCH_BIN
and CUDA_ARCH_PTX
, to only contain the CUDA compute capability supported by my graphics card, which can be found here.
i have tried it on two pc’s but it doesnt’ work for me
Edit:
i have tried it with a Geforce GTX 980 and a Geforce GTX 780. so generation is kepler (and Maxwell) with architecture 3.0 3.5
if nessesary i can try it on other pc too. But for the next two weeks i can let one pc in this configuration, if you need more testing.
One fast workaround is to use as «CUDA_HOST_COMPILER» the «clang-3.5»
@StevenEWright Hey, can you give an example what exactly you changed in -DCUDA_ARCH_BIN=xx
and `-DCUDA_ARCH_PTX=xx
? I am using Nvidia 940M and I can’t find in the link you posted how to deduce from the product page what version I should include.
The Geforce 940m is 5.0 compatible.
@jamesapollo2016 I understand it uses CUDA Compute 5.0, but what what should I insert in -DCUDA_ARCH_BIN=xx
and -DCUDA_ARCH_PTX=xx
? The options seem to be 20 21 30 35, not 5.
This is what I get if I set no changes:
-- NVIDIA CUDA
-- Use CUFFT: YES
-- Use CUBLAS: NO
-- USE NVCUVID: NO
-- NVIDIA GPU arch: 20 21 30 35
-- NVIDIA PTX archs: 30
-- Use fast math: NO
I tried all combinations of
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ -DBUILD_opencv_legacy=OFF -DCUDA_ARCH_BIN=2.0 -DCUDA_ARCH_PTX=2.0 .
Where I changed the two 2.0
variables in the examples to 2.0 2.1 3.0 3.5, and no luck
Compiled with 5 just fine for me using cmake-gui. Compiling CUDA for a single version is MUCH FASTER.
@jamesapollo2016
- Thats is a cmake file that detects CUDA. CUDA is indeed detected. That is not the issue.
- That cmake file is not self-explanatory. It does not relate to the memcpy error in a way I can understand. The cmake command works, its the make that fails.
I tried addin 50. I get the exact memcpy error. It might not even be in
those variables.
On May 15, 2016 20:57, «Philip» [email protected] wrote:
Philip’s message seems to be deleted, its available here:
@guysoft <https://github.com/guysoft> to your question what exactly you
> have to insert here
>
> -DCUDA_ARCH_PTX=xx
> -DCUDA_ARCH_BIN=xx
>
> you can insert 50 for compute capability 5.0 in both options. The defaults
> 20 21 30 and 35 are for the versions 2.0,2.1,3.0 and 3.5 which are included
> in most the gpus where these lines were added
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly or view it on GitHub
> <https://github.com/Itseez/opencv/issues/6500#issuecomment-219300448>
since my assumption was wrong after testing this i deleted this again. Since you have to state the version with a dot.
cmake-gui output:
Commandline options:
-DCUDA_ARCH_BIN:STRING="5.0" -DCUDA_ARCH_PTX:STRING="5.0"
Cache file:
CUDA_ARCH_BIN:STRING=5.0
CUDA_ARCH_PTX:STRING=5.0
so this wouldn’t change a thing. Seems to be different issue for you
So did you try already the option «5.0» since this has to be compatible with your 940M?
@Dikay900 I did it with the dots. I am using the commandline, this is my command:
cmake -DBUILD_opencv_legacy=OFF -DCUDA_ARCH_BIN=5.0 -DCUDA_ARCH_PTX=5.0 -DWITH_CUDA=ON .
can you try making a build folder for building the source and then build again using the commandline option my gui is stating? So something like this:
mkdir build
cd build
cmake -DBUILD_opencv_legacy=OFF -DCUDA_ARCH_BIN:STRING="5.0" -DCUDA_ARCH_PTX:STRING="5.0" -DWITH_CUDA=ON ..
make
@Dikay900 Does not work, get the same error. I should stress, opencv compiles fine if I do -DWITH_CUDA=ON
. Its quite likely something to do with the CUDA settings/code.
I have tried it also on 3 clean installations with ubuntu 16.04 and the «nvidia-cuda-toolkit» isntalled from synaptic. All failed, are you all sure you have the same system?
@guysoft
as i write above a workaroud was to compile it with CUDA_HOST_COMPILER=clang-3.5 (you need to install the clang 3.5 first and if i remember right, you need to Disable the tests also)
@tommy87 It works if you disable the nvidia cuda with -DWITH_CUDA=OFF
. But then you wont have GPU acceleration. Also you must make clean and delete all cache cmake files. After I extracted opencv I create a git repo and add all extracted files to it. That way I can do git clean -df
and delete all the cmake files, they seem to remember settings otherwise.
The reason I don’t want to use clang is because I am using the OpenCV installtion to link against Caffe. Correct me if I am wrong, but using different compiles should result in a linking error.
Im Not sure if it leeds to a linking error… I want to used it also with Caffe, but i hadn’t the time to test it yet. But maybe i will try this today and than i can tell you if it works or not
@guysoft i have tried to compile caffe and i didnt get linking errors
So i have compiled openCV with CUDA and clang 3.5 and the NVIDIA version of caffe 0.15 with the cc compiler. To get the cc compiler running you need to follow this https://github.com/BVLC/caffe/issues/4046
@all
the solution for caffe is to add «set(CMAKE_CXX_FLAGS «${CMAKE_CXX_FLAGS} -D_FORCE_INLINES»)» to the CMakeList.txt i have tried it with opencv also but i was unable to find the right place to insert this. Maybe someone knows better where the line must be insert (if you tell me, i can try it by myself)
Simple replace in opencv/cmake/OpencvDetectCuda.cmake
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
to
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
it’s work for me!
@chapaev28 ‘s solution works. Added a pull request.