Embarcadero RoundTo Console vs VCL - c++builder

I use Embarcadero C++Builder 10.2 Tokyo (Community Edition).
I try to use the RoundTo() function. I can use it in a VCL project by adding the <Math.hpp> header, but in a Console project I can not use this function at all. I get 2 error messages:
[ilink32 Error] Error: Unresolved external '__fastcall System :: Math :: RoundTo (const long double, const signed char)' referenced from C: \ USERS \ ... \ ROUNDTOCONSOLE \ WIN32 \ DEBUG \ ROUNDTOCONSOLE.OBJ
and
[ilink32 Error] Error: Unable to perform link
Please tell me how to use this function in a Console project? What library or namespace do I need to use? And why can I use it in a VCL project, is there a problem in the console?

Related

Unable to compile C++ code (having OpenCV usage) to wasm

I have the following C++ code. Here I am OpenCV library for some image processing-related operations.
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <opencv/cv.hpp>
using namespace cv;
using namespace std;
int main()
{
try
{
Mat frame, g_frame, r_frame; //, reduced_frame;
int REDUCTION = 3;
//--- INITIALIZE VIDEO_CAPTURE
VideoCapture cap;
// open selected camera using selected API
cap.open(cv::CAP_DSHOW);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
//--- GRAB AND WRITE LOOP
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
// image_window win;
while(true)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// flipping the image
cv::flip(frame, frame, 1);
cv::resize(frame, frame, cv::Size(), 2.0f, 2.0f, cv::INTER_CUBIC);
// converting image to grey scale image
cv::cvtColor(frame, g_frame, CV_BGR2GRAY);
// reducing size of image
cv::resize(g_frame, r_frame, cv::Size(), 1.0/REDUCTION, 1.0/REDUCTION, cv::INTER_CUBIC);
cv::imshow("Live", frame);
if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC
}
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}
return 0;
}
when I am trying to compile this code to wasm using the following command:
emcc -msse3 -msimd128 -std=c++11 -O3 -I ../opencv/build/include main.cpp -lpthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s TOTAL_MEMORY=1024MB -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s WASM=1 -o main.js
Then I am getting the following errors:
error: undefined symbol: _ZN2cv12VideoCapture4openEi (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN2cv12VideoCapture4openEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCapture4readERKNS_12_OutputArrayE (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCapture4readERKNS_12_OutputArrayE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCaptureC1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCaptureC1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCaptureD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCaptureD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv3Mat10deallocateEv (referenced by top-level compiled C/C++ code)
warning: __ZN2cv3Mat10deallocateEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv4flipERKNS_11_InputArrayERKNS_12_OutputArrayEi (referenced by top-level compiled C/C++ code)
warning: __ZN2cv4flipERKNS_11_InputArrayERKNS_12_OutputArrayEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6String10deallocateEv (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6String10deallocateEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6String8allocateEm (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6String8allocateEm may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6imshowERKNS_6StringERKNS_11_InputArrayE (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6imshowERKNS_6StringERKNS_11_InputArrayE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv7waitKeyEi (referenced by top-level compiled C/C++ code)
warning: __ZN2cv7waitKeyEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii (referenced by top-level compiled C/C++ code)
warning: __ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv8fastFreeEPv (referenced by top-level compiled C/C++ code)
warning: __ZN2cv8fastFreeEPv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZNK2cv12VideoCapture8isOpenedEv (referenced by top-level compiled C/C++ code)
warning: __ZNK2cv12VideoCapture8isOpenedEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: 'C:/emsdk/node/12.18.1_64bit/bin/node.exe C:\emsdk\upstream\emscripten\src\compiler.js C:\Users\Nitin\AppData\Local\Temp\tmppq_ad1ya.txt' failed (1)
Please help me.
The above problem is solved by using the suggestions provided in the error itself.
emcc -msse3 -msimd128 -std=c++11 -O3 -I ../opencv/build/include main.cpp -lpthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s TOTAL_MEMORY=1024MB -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s WASM=1 -s LLD_REPORT_UNDEFINED -s ERROR_ON_UNDEFINED_SYMBOLS=0 -o main.html
However, while opening the main.html file in the browser. I am now getting the following error.
CompileError: WebAssembly.instantiate(): Compiling function #607 failed: invalid value type 'Simd128', enable with --experimental-wasm-simd #+105826
Please help me in solving this.
You have to run your browser with the option --experimental-wasm-simd, as SIMD isn't a part of the webassembly spec (yet).
You need to follow the suggestions given in the errors. Check line number 2 and 3 of your errors.

Unable to link C runtime library (libcmt.lib) using lld-link.exe (Windows)

I'm writing a language using LLVM. I'd like to avoid having to package clang and simply use the LLVM tools (ex. lld, lld-link). I've been trying to invoke the printf function from my simple IR code (testinput.ll):
; ModuleID = 'Test2'
source_filename = "entry"
#str_0 = private unnamed_addr constant [13 x i8] c"Hello world!\00"
declare i32 #printf(i8*, ...)
define i32 #main() {
entry:
%anonymous_10 = call i32 (i8*, ...) #printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* #str_0, i32 0, i32 0))
ret i32 1234
}
But I keep receiving errors no matter what I try:
$ clang-cl -fuse-ld=lld-link testinput.ll "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\spectre\x64\libcmt.lib"
Note: I've chosen the link randomly "... spectre\x64\libcmt.lib ..." by simply searching for libcmt.lib on the system.
Error:
C:\Program Files\LLVM\bin\lld-link: warning: libcmt.lib(loadcfg.obj): undefined symbol: __enclave_config
error: link failed
clang-cl.exe: error: linker command failed with exit code 1 (use -v to see invocation)
I'm using Windows 10 (x64) with LLVM 5.0. Interestingly, using link.exe (Windows' VS tools' linker) everything works fine (which is what clang uses under the hood in my case).
I've read in this article:
... As I wrote earlier, __enclave_config is a variable that is filled in by the linker, but you have to use the VC linker, and a linker new enough to be able to automatically fill it in. ...
I believe the problem here is libcmt.lib and the lld-link linker. Is the lld-link version (LLVM 5.0) incompatible with the libcmt.lib that I'm using, is that the problem?
Edit: I've managed to track down what clang does behind the scenes, and have found it using the following command:
lld-link -out:a.exe -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17763.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17763.0\\um\\x64" -nologo "test.obj"
Clearly it's using lld-link, and it's working. However, strangely enough, it only compiles without errors if the input object file was compiled to .LL (LLVM IR) using clang (maybe using -fuse-ld=lld -v options?).
What's weird about this, is that upon inspection of the output .LL file from clang (test.ll) the full, source code (in IR) definitions of printf (and some other *printf functions used by it) is present (in the output .LL file).
So, somehow it's getting the definitions of printf itself inside the output .LL, IR code file.
As far as I know, you can't just $ llc libcmt.lib testinput.ll? That'd be the linker's job... (llc accepts only one positional argument)
The error that I'm getting once I try the same lld-link command and arguments with my testinput.ll file (not outputted from clang) is the following:
lld-link: error: <root>: undefined symbol: _mainCRTStartup
lld-link: error: undefined symbol: _printf
Turns out, it was much much more simple than I anticipated. Maybe if the errors were at least somewhat helpful, I could have avoided all this confusion...
I've figured it out by comparing clang's output LL file, and noticed a curious line at the beginning:
target triple = "x86_64-pc-windows-msvc"
Once I added it to my testinput.ll file, everything worked flawlessly with lld-link. Hurray!

Datasnap - How to fix linker errors when using TFDGUIxWaitCursor?

I have a following problem when I want compile my Datasnap ISAPI DLL project using C++ Builder 10.2:
Create new Datasnap WebBroker Application as ISAPI DLL and using
TDSServerModule option
Open WebModule1 designer and add TFDGUIxWaitCursor component
In project options deselect "Link with Dynamic RTL" and "Link with runtime packages"
Build
Then a bunch of linker errors are generated:
[ilink32 Error] Error: Unresolved external 'GetDpiForMonitor'
referenced from C:\PROGRAM FILES
(X86)\EMBARCADERO\STUDIO\19.0\LIB\WIN32\DEBUG\VCL.LIB|Vcl.Forms
[ilink32 Error] Error: Unresolved external
'SHCreateItemFromParsingName' referenced from C:\PROGRAM FILES
(X86)\EMBARCADERO\STUDIO\19.0\LIB\WIN32\DEBUG\VCL.LIB|Vcl.Dialogs
[ilink32 Error] Error: Unresolved external 'BeginBufferedPaint'
referenced from C:\PROGRAM FILES
(X86)\EMBARCADERO\STUDIO\19.0\LIB\WIN32\DEBUG\VCL.LIB|Vcl.Controls
....
Similar errors are shown when targeting Windows 64 bit platform. What I noticed is that TFDGUIxWaitCursor is the one causing this as compiling the project prior placing that component is successful. It even compiles fine if the component is on the web module but if step 3 is not performed. How to solve this and get successful compile when steps 2 and 3 are applied?
Adding the following lines to the WebModule.cpp file resolves the issue:
#pragma comment(lib, "SHCore")
#pragma comment(lib, "UXTheme")
#pragma comment(lib, "shell32")
#pragma comment(lib, "WINDOWSCODECS")

Can't build OpenCV 3.1 on Windows (using MinGW)

I need to build OpenCV from source, because I want to make modifications to it. So using pre-built binaries is not an option for me. I'm doing this on Windows 8. I do not have MS Visual Studio, and I don't want to use it.
Here is how I reproduce the build error:
I git clone https://github.com/opencv/opencv
I use CMake 3.7.1, press Configure, then press Generate. It seems to work (no errors). I named the output folder opencv/release.
I go to the opencv/release folder, and type mingw32-make.
Eventually, after compiling for a while, it displays the following error message:
Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj
modules\core\src\parallel.cpp:135:43: error: operator '&&' has no right operand
modules\core\src\parallel.cpp: In function 'void cv::parallel_for_(const cv::Range&, const cv::ParallelLoopBody&, double)':
modules\core\src\parallel.cpp:311:52: error: 'parallel_for_pthreads' was not declared in this scope parallel_for_pthreads(range, body, nstripes);
^
modules\core\src\parallel.cpp: In function 'int cv::getNumThreads()':
modules\core\src\parallel.cpp:370:50: error: 'parallel_pthreads_get_threads_num' was not declared in this scope return parallel_pthreads_get_threads_num();
^
modules\core\src\parallel.cpp: In function 'void cv::setNumThreads(int)':
modules\core\src\parallel.cpp:431:46: error: 'parallel_pthreads_set_threads_num' was not declared in this scope parallel_pthreads_set_threads_num(threads);
^
modules\core\CMakeFiles\opencv_core.dir\build.make:990: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj' failed mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj] Error 1
Note: I tried to compile both with and without TPP (in the CMake config), and I get the same error message.
Also, I read the other similar questions on StackOverflow and the answers do not help.

Emscripten clang hello_world.cpp link error

I am trying to follow the tutorial on Emscripten setup.I have installed the SDK and now trying to test clang compilation.
Trying simple : clang tests/hello_world.cpp I am getting the following error:
c:\Program Files\Emscripten\emscripten\1.13.0>clang++
tests/hello_world.cpp hello_world-005255.o : error LNK2019:
unresolved external symbol printf referenc ed in function main LINK :
error LNK2001: unresolved external symbol mainCRTStartup hell.exe :
fatal error LNK1120: 2 unresolved externals clang++.exe: error: linker
command failed with exit code 1120 (use -v to see inv ocation)
I am executing the command in VS 2010 cmd and my system is 64bit (Emscripten version is 64bit too)

Resources