OpenCV tries to load uninstalled Cuda dlls - opencv

I had installed CUDA 9.1 previously and tested my OpenCV with the code below, all worked fine but later on I had to remove it and install 8.0. Now the below code gives errors since the previous dlls are searched.
Here is my test code:
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"
using namespace cv;
int main(int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("hdd.png", cv::IMREAD_GRAYSCALE);
cv::cuda::GpuMat dst, src;
src.upload(src_host);
cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY);
cv::Mat result_host(dst);
cv::namedWindow("Result", cv::WINDOW_NORMAL);
cv::imshow("Result", result_host);
cv::waitKey();
}
catch (const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}
Here is the error:
The code execution cannot proceed because cudart64_91.dll was not found. Reinstalling the program may fix this problem.
It asks for 2-3 more dlls when I click on OK button, but I am not gonna write them here as I suspect the problem arises from the same source.
The problem is rather obvious. The dlls which are tried to be loaded, belong to the uninstalled version of CUDA (9.1), whereas I have now 8.0. I do not know why my Visual Studio 2013 tries to load the previous ones still.
Before anyone asks, yes I do have my newer installation (8.0) in my PATH. I am using Windows 10 x64, if it matters.

The real problem behind your error:
OpenCV was built with CUDA 9.1, this will not change even if you change the CUDA installation, thus it will the DLLs from CUDA 9.1 will always be required for every program that is compiled with OpenCV. Maybe a module does not have this linked and you can use it... but I am almost sure the main ones do and you won't be able to use them.
Possible solutions:
Build OpenCV with CUDA 8.0 then it will require is CUDA 8.0 DLLs and not the 9.1 ones.
Install CUDA 9.1. Both CUDA can be installed in the same computer, that is why they have this _80 or _91, this way you can have both paths and the computer decide which one is needed... I think it is not possible to have BOTH in the same program though, so be careful with this option. If it is only used by OpenCV then it will be ok.
I would recommend the first option, it is safer to stick to one library version...

Related

Program compiles but doesn't do anything

I've recently started exploring and reading about Microchip's PIC32 MCUs, most specifically for motor control. I had some job done over the years but was a long while and haven't used the IDE with evaluation board since university years. Been using Arduino-compatible boards since or boards, compatible with the Arduino IDE.
So I'm running MPLAB X IDE v6.05 with the latest XC32 Compiler.
My Development board is DT100113 Curiosity Pro board, utilizing PIC32MK0512MCJ064 MCU and an on-board PicKit4 (PKoB4) for programming/debugging/serial connection purposes.
What I try to do is light up the two user LEDs on pins RA10 and RE13 respectively.
As I begin with creating new project, select my device, my program/debug tool and give my project a name, next step is to create a new main.c file.
I create the file and write the following:
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
int main(int argc, char** argv) {
//Define corresponding port bits as outputs (0 = output, 1 = input).
TRISAbits.TRISA10 = 0;
TRISEbits.TRISE13 = 0;
//Latch the outputs to HIGH (1) and hold.
while(1)
{
LATAbits.LATA10 = 1;
LATEbits.LATE13 = 1;
}
return (EXIT_SUCCESS);
}
When I build and run it - nothing happens. Build is successful, connected to programmer, erase/flash device OK, but nothing with the LEDs.
I think I'm missing the #pragma directives (read about that it must be defined first prior anything else), but am unaware on how to set configuration bits (used peripherals, internal clock speed, etc.).
Any pointers to how-to articles, posts, etc. will be highly appreciated. I was not able to find step-by-step tutorial for my development board so far :((
Thank you in advance!
Cheers,
Iliyan
I tried creating a new project, it compiled and ran, but the LEDs were not lit.
Obviously was missing some vital parts in the code.
Application software examples and driver libraries are included as part of the MPLAB Harmony V3 Framework. Add Harmony to 'Embedded' under the 'Tools' tab of the MPLAB IDE.

Unable to link with opencv libraries

I trying use OpenCV with visual studio 2017 and running this example code is giving me build time errors
I have provided the right directories to the libraries. I have gone through many tutorials and questions/answers on stack overflow so many times but haven't succeeded in fixing the problem.
#include "opencv2\opencv.hpp"
#include "opencv2\core.hpp"
#include "pch.h"
#include "opencv2\core\core.hpp"
using namespace cv;
int main(int argv, char** argc)
{
Mat test = imread("lena.jpg", IMREAD_UNCHANGED);
imshow("tst", test);
waitKey();
}
I get the following errors
C2065 'IMREAD_UNCHANGED':undeclared identifier
C3861 'imread': identifier not found
C3861 'imshow': identifier not found
C3861 'waitkey': identifier not found
Intellisense gives me all the library suggestions when I type the code but it throws errors after build.

Compile a command line script for iOS

I coded an iOKit fuzzer for iOS. Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/vm_map.h>
#include <IOKit/IOKitLib.h>
int main()
{
io_service_t service = IOServiceGetMatching(kIOMasterPortDefault, IOserviceMatching("IOUSBHIDDriver")); // change service each time
if(!service)
{
return -1;
}
io_connect_t connect;
kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &connect);
if(kr != kIOReturnSuccess)
{
return -1;
}
uint32_t selector =3;
uint64_t input[0];
input[0] = 0x44444444444;
IOConnectCallMethod(connect, selector, input, 1, 0, 0, NULL, NULL, NULL, NULL);
printf("Did it crash? No? Do it again! -Toxic\n");
}
I've been trying to compile this with GCC for a while now, but I get all kinds of errors. I'd like to know if anyone know exactly how to compile a command line tool for iOS. Thanks.
As far as I'm aware, there's no such thing as a command line tool for (non-jailbroken) iOS, although you can output to the log using NSLog from an App. Also, Apple's toolchain for iOS uses clang (llvm) although the 'gcc' command is typically aliased to clang. The easiest way to get a script is to create a test project in Xcode, build it and look at the build log. This shows you all the commands that were run with what arguments.
Idk have you found the solution or not but anyways.
If you want to conpile with clang on device type:
clang -framework IOKit your_app.c -isysroot /var/theos/sdks/iPhoneos_whatever_sdk_you_have -o output
And this should compile.
On the mac same just without isysroot & /var...
And if you try in xcode make sure that the driver can run inside the sandbox and include iokit headers
:D

Bounds checking of std::vector (and other containers) in clang?

In clang, is there a way to enable bounds checking for [] access to std::vectors and other STL containers, preferably when building in debug mode only?
I just spent hours hunting down a subtle bug that turned out to be caused by us accessing past the end of a std::vector. It doesn't need to do anything clever when it detects the error, just trap in the debugger so that I can find out where it happened and fix it in the code.
Is there a way to do this other than "create your own type that inherits from std::vector", which I'd like to avoid?
(I'm using clang version 3.1 if that makes a difference.)
libstdc++ has a mature debug mode using -D_GLIBCXX_DEBUG.
libc++ also has a debug mode using -D_LIBCPP_DEBUG but as we can see this mailing list discussion: Status of the libc++ debug mode it is incomplete:
| My understanding is that this work was never completed and it's
probably broken/incomplete.
That is correct.
It’s on my list of things to fix/implement, but it’s not something that I will get to anytime soon.
It does seem to work for std::vector on 3.4 and up see it live, give the following program:
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v = {0,1,2,3} ;
std::cout << v[-1] << std::endl ;
}
it generates the following error:
vector[] index out of bounds
Aborted
If you're using Linux or OS X you should look into the address sanitizer:
http://clang.llvm.org/docs/AddressSanitizer.html
It introduces a 2x slowdown, but does a bunch of memory checking and may catch your bug.
Another amazing tool that has saved me countless times is valgrind. If you can run with valgrind it will catch a ton of memory bugs and leaks.
#define _GLIBCXX_DEBUG
This enables all kinds of inline checking (see vector and debug/vector)

dyld API on iPhone - strange output

I have three question for you, all related to dyld :)
I have been using this dyld man page as a basis. I have compiled the following code and successfully executed the binary on my jailbroken device.
#include <stdio.h>
#include <mach-o/dyld.h>
int main(int argc, const char* argv[]) {
uint32_t image_count, i;
image_count = _dyld_image_count();
for (i = 0; i < image_count; i++) {
printf("%s\n", _dyld_get_image_name(i));
}
return 0;
}
I thought that these functions let me find all the shared libraries that are loaded in my program's address-space. On my mac, the output is pretty straightforward: It shows the paths to all the libraries that are currently loaded in memory. On my iPhone the output is nearly the same - i also get filepaths - but there are no files at the specified location. (On my mac on the other hand, i can locate the files!)
This is a sample line from the output:
/usr/lib/system/libdyld.dylib
According to ls, iFile and all the other tools i've used, this directory (/usr/lib/system/) is empty. Why? Where are those files?
Another thing i'd like to know is: Is it possible to locate a library in memory? From what offset to what offset the library is mapped into memory? I think i know how to find the beginning but i have no idea how to find the end of the library. To find the beginning, i'd use the address returned by _dyld_get_image_header - Is that correct?
Last question: I wanted to load a dynamic lib system-wide so i assumed i could use DYLD_INSERT_LIBRARIES to do just that. However, every binary i try to execute after inserting my lib crashes and produces a bus error! Did i forget something or is it the dynamic library that causes the crash?
the libraries are located at :
/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv6 (_armv7)
This is a big file were all the single libraries have been joined into one large one.
See http://iphonedevwiki.net/index.php/MobileSubstrate for hooking on jailbroken device
Yes one can determine the position of a dylib in memory, even on non jailbroken devices.
parse the LC_SEGMENT(_TEXT)-Section Header(_text) of the library then you can get the base address of the library and the size of the TEXT __text segment. Then query for the vmslide. Add this to the base address of the TEXT __text.
A detailed description of the mach-o file format can be found here:
https://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html. Pay special attention to "segment_command"-structure.

Resources