# Cpp sample program addingimages.cpp fails in runtime

**URL:** <https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162>\
**Category:** C++\
**Tags:** programming\
**Created:** [February 28, 2023, 9:26am UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162 "2023-02-28T09:26:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 9:26am UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/1 "2023-02-28T09:26:35Z")

</div>

Program gives on execution time error:  
Unhandled exception at 0x00007FF9C8FB441C in Project1.exe: Microsoft C++ exception: std::bad\_alloc at memory location 0x0000005C20AFE9F0.

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 9:48am UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/2 "2023-02-28T09:48:17Z")

</div>

Previous remark was for static library use  
Now I tried dynamic libraries using case, but got linker error.

| Severity | Code | Description | Project | File | Line | Suppression State |
| --- | --- | --- | --- | --- | --- | --- |
| Error | LNK1107 | invalid or corrupt file: cannot read at 0x390 | Project1 | C:\Users\Raivo\opencv\build\x64\vc15\bin\opencv\_videoio\_ffmpeg460\_64.dll | 1 | |

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [February 28, 2023, 9:55am UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/3 "2023-02-28T09:55:15Z")

</div>

> [@raivore](#):
>
> Now I tried dynamic libraries using case, but got linker error.

Are you manually adding `C:\Users\Raivo\opencv\build\x64\vc15\bin\opencv_videoio_ffmpeg460_64.dll` as a link library?

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 11:02am UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/4 "2023-02-28T11:02:16Z")

</div>

Yes I added this library

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [February 28, 2023, 11:03am UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/5 "2023-02-28T11:03:51Z")

</div>

Remove it and refer to my reply to your previous question

> [@VIsual Studio problems](https://forum.opencv.org/t/visual-studio-problems/12120/4):
>
> Are you adding C:\Users\Raivo\opencv-4.7.0\build\bin\Debug\opencv\_calib3d470d.dll to Properties-\>Linker-\>Input-\>Additional Dependencies? instead of C:\Users\Raivo\opencv-4.7.0\build\lib\Debug\opencv\_calib3d470d.dll? If so that’s your problem, you need to add the .lib to the linker for compilation and the .dll to your system/user path for runtime.

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 1:51pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/6 "2023-02-28T13:51:10Z")

</div>

Now is new error

| Severity | Code | Description | Project | File | Line | Suppression State |
| --- | --- | --- | --- | --- | --- | --- |
| Error | LNK1107 | invalid or corrupt file: cannot read at 0x308 | Project1 | C:\Users\Raivo\opencv\build\x64\vc15\bin\opencv\_videoio\_msmf460\_64.dll | 1 | |

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 28, 2023, 1:55pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/7 "2023-02-28T13:55:03Z")

</div>

1. those are NOT meant to be linked directly, so remove it  
(the videoio module will load those dynamically, on its own)
2. (again !) IF AT ALL, add `.lib` files to your linker, not `.dll`

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [February 28, 2023, 2:01pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/8 "2023-02-28T14:01:18Z")

</div>

Please read the last reply I gave you to your previous post

> [@VIsual Studio problems](https://forum.opencv.org/t/visual-studio-problems/12120/4):
>
> Are you adding C:\Users\Raivo\opencv-4.7.0\build\bin\Debug\opencv\_calib3d470d.dll to Properties-\>Linker-\>Input-\>Additional Dependencies? instead of C:\Users\Raivo\opencv-4.7.0\build\lib\Debug\opencv\_calib3d470d.dll? If so that’s your problem, you need to add the .lib to the linker for compilation and the .dll to your system/user path for runtime.

Please don’t create topics if you are not going spend the time to read the replies people make to them!

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 3:59pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/9 "2023-02-28T15:59:52Z")

</div>

I reality I added .lib files for linker. I don’t know, why it looks for dll-s.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 28, 2023, 4:40pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/10 "2023-02-28T16:40:54Z")

</div>

there is no opencv\_videoio\_ffmpeg460\_64.lib or opencv\_videoio\_msmf460\_64.lib

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 4:46pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/11 "2023-02-28T16:46:44Z")

</div>

Sorry. I am novice in this forum.  
But I overcome this problem by installin opencv-4.6.0 from sources and it works fine

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 5:05pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/12 "2023-02-28T17:05:32Z")

</div>

Also I have installed opencv-4.7.0 and learning its capabilities.

---

<div class="post-metadata">

**Author:** ![raivore](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@raivore](https://forum.opencv.org/u/raivore)\
**Post date:** [February 28, 2023, 6:45pm UTC](https://forum.opencv.org/t/cpp-sample-program-addingimages-cpp-fails-in-runtime/12162/13 "2023-02-28T18:45:25Z")

</div>

Version 4.7.0 don’t work properly. Libraries build gives error - Error C2001 newline in constant opencv\_objdetect C:\Users\Raivo\opencv-4.7.0\build\modules\objdetect\opencl\_kernels\_objdetect.cpp 817

And both static library example gives memory allocation error and dynamic library using example gives error on linking -

| Severity | Code | Description | Project | File | Line | Suppression State |
| --- | --- | --- | --- | --- | --- | --- |
| Error | LNK1107 | invalid or corrupt file: cannot read at 0x368 | Project1 | C:\Users\Raivo\opencv-4.7.0\build\install\x64\vc17\bin\opencv\_calib3d470.dll | 1 | |
