Hello World for KDE in Qtcreator - project

I have just begun programming for KDE, the problem I face is I don't know what exactly should be the pro file for a KDE project, I have an idea for cmake though
I also tried in pro file:
LIBS += -lkdeui
I still get problem KApplication not found
Code main.cpp:
#include <cstdlib>
#include <KApplication>
#include <KAboutData>
#include <KCmdLineArgs>
#include <KMessageBox>
#include <KLocale>
int main (int argc, char *argv[])
{
KAboutData aboutData("tutorial1",0,ki18n("Tutorial 1"),"1.0",ki18n("Displays a KMessageBox popup"),KAboutData::License_GPL,ki18n("(c) 2007"),ki18n("Some text..."),"http://example.com/","submit#bugs.kde.org");
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication app;
KGuiItem yesButton( i18n( "Hello" ), QString(),
i18n( "This is a tooltip" ),
i18n( "This is a WhatsThis help text." ) );
return
KMessageBox ::questionYesNo
(0, i18n( "Hello World" ), i18n( "Hello" ), yesButton )
== KMessageBox ::Yes? EXIT_SUCCESS: EXIT_FAILURE;
}
and tutorial.pro file is:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
LIBS += -lkdeui

You need to install development files for kde libraries, these are missing. I don't know which Linux distro you are using (if any) but, for example, in Debian the required package is called kdelibs5-dev.
You will probably also need to specify the include path for these development files after installing the package. Like INCLUDEPATH += /usr/include/KDE

Related

Process finished with exit code -1073741515 (0xC0000135) while using SDL2 in CLion [duplicate]

I've been trying to run OpenCV using CLion IDE under Windows. When I try to run this sample code for loading and displaying an image
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread("earth.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
I get the error statement:
Process finished with exit code -1073741515 (0xC0000135)
As for the content in my CMakeLists.txt, it looks like this:
cmake_minimum_required(VERSION 3.6)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\mingw-build\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(openCV main.cpp)
# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# linking
target_link_libraries(openCV ${OpenCV_LIBS})
Thanks for helping me with this.
You need to add OpenCV binary path with DLLs to your PATH BEFORE CLion start.
I do it from script:
=== CLionWithMingwAndOpenCV.bat ==========================
#echo off
set PATH=C:\mingw-w64\x86_64-5.2.0-win32-seh-rt_v4-rev0\mingw64\bin;D:\opencv\release\bin;%PATH%
"C:\Program Files (x86)\JetBrains\CLion XXXX\bin\clion64.exe"
=== ==========================

JNI header missing in Objective-C

I have a file.c in my project which has #include <jni.h> header file. What is the process to include this header file in project or macOS?
Let's say you have following code
#include "jni.h"
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
options[0].optionString = "-Djava.class.path=_HERE_GOES_LOCATION_OF_JNICOOKBOK_/jnicookbook/recipeNo051/target";
vm_args.options = options;
vm_args.ignoreUnrecognized = 0;
vm_args.version = JNI_VERSION_1_8;
vm_args.nOptions = 1;
int status = JNI_CreateJavaVM (&jvm, (void **) &env, &vm_args);
if (status < 0 || !env) {
printf ("Error - JVM creation failed\n");
return 1;
}
jclass cls_Main = (*env)->FindClass (env, "recipeNo051/Main");
jmethodID method_displayMessage = (*env)->GetStaticMethodID (env, cls_Main, "displayMessage", "()V");
(*env)->CallStaticVoidMethod(env, cls_Main, method_displayMessage);
(*jvm)->DestroyJavaVM( jvm );
}
return 0;
}
in order to run it you will need
location of libjvm.dylib
location of headers
location of compiled Java classes that are called from main.m
Let's start with libs and headers. You have to make sure that following paths are searched for includes (note that I am using jdk-11.0.4):
/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home/include
/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home/include/darwin/
You have to make sure that following path is added to Library Search Path and to Runpath Search Paths
/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home/lib/server
You should have settings like that:
Make sure you are linking your code with libjvm.dylib. Add it inside Build Phases
where you can specify it's location by choosing Add Other...
Run your code, but! Make sure to ignore SIGSEGV before calling method JNI_CreateJavaVM. You can ignore it inside lldb console
(lldb) process handle --pass true --stop false SIGSEGV
After you continue, you can see your JVM instance calling classes from the recipeNo051.
Source code of class: recipeNo051/Main can be found here: https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo051
Update
step by step instructions: http://www.owsiak.org/running-jni-based-code-inside-xcode/
video tutorial: https://youtu.be/WEA-3uI7Y18

getting error in running cmake std Tutorial step 2 example

I am totally new to cmake and its syntax .But fortunately I am able to run the cmake tutorial step 1 as per the introductions mention on below links :
https://cmake.org/cmake/help/latest/guide/tutorial/index.html
But I am totally stucked at step 2 project to run using cmake.
I have created the step 2 project and understand the syntax to link the library for doing square root of a number, But I did not understand how to run this as I am getting below error :
user#server:~/TER_CMAKE/Tutorial/step2_build$ cmake ../step2
CMake Error at CMakeLists.txt:19 (add_subdirectory):
The binary directory
/home/user/TER_CMAKE/Tutorial/step2/MathFunctions
is already used to build a source directory. It cannot be used to build
source directory
/home/user/TER_CMAKE/Tutorial/step2/MathFunctions
Specify a unique binary directory name.
-- Configuring incomplete, errors occurred!
The example is available at below location for step 2 under heading Adding a Library (Step 2)..
https://moodle.rrze.uni-erlangen.de/pluginfile.php/14829/mod_resource/content/5/CMakeTutorial.pdf
My intention is to run my example this way
step2_build$ cmake ../step2
step2_build$ cmake --build .
step2_build$ ./Tutorial 121
As I am not sure that is it good to ask this way on this platform ,But as I do not have any other guidance .I am doing this by my own .
Note: I do not wants to use any tool to run my step 2 example.I wants to run everything using command prompt and cmake command only .where I can understand the cmake .
Edit:
Adding my CMakeLists.txt =
cmake_minimum_required(VERSION 3.5)
#set the project name
project(Tutorial VERSION 1.0)
#specify the c++ std
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(USE_MYMATH "Use tutorial provided math implementation" ON)
#Configure a header file to pass the version number to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)
#add the MathFunctions Library
add_subdirectory(MathFunctions)
if(USE_MYMATH)
add_subdirectory(MathFunctions)
list(APPEND EXTRA_LIBS MathFunctions)
list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
endif()
#add the executable
add_executable(Tutorial tutorial.cpp)
target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
${EXTRA_LIBS}
)
My Source tutorial.cpp file:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#ifdef USE_MYMATH
#include "MathFunctions.h"
#endif
#include "TutorialConfig.h"
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 2) {
cout << "Usage: " << argv[0] << " number" << endl;
return 1;
}
// convert input to double
const double inputValue = atof(argv[1]);
// calculate square root
#ifdef USE_MYMATH
const double outputValue = mysqrt(inputValue);
#else
const double outputValue = sqrt(inputValue);
#endif
cout << "The square root of " << inputValue << " is " << outputValue << endl;
return 0;
}
ToturialConfig.h.in file :
#define Tutorial_VERSION_MAJOR #Tutorial_VERSION_MAJOR#
#define Tutorial_VERSION_MINOR #Tutorial_VERSION_MINOR#
#cmakedefine USE_MYMATH
EDIT:
Step2 has a folder MathFuctions,Which has Cmake file mysqrt.cpp file
/TER_CMAKE/Tutorial/step2/MathFunctions/CMakeLists.txt
add_library(MathFunctions mysqrt.cpp)
/TER_CMAKE/Tutorial/step2/MathFunctions/mysqrt.cpp
#include <iostream>
// a hack square root calculation using simple operations
double mysqrt(double x)
{
if (x <= 0) {
return 0;
}
double result = x;
// do ten iterations
for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
double delta = x - (result * result);
result = result + 0.5 * delta / result;
std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
return result;
}
In case USE_MYMATH variable is set add_subdirectory(MathFunctions) is invoked twice. You need to decide and remove one of the occurrences on lines 16 and 19 in you CMakeLists.txt.
Two issues I can see:
You're adding the subdirectory "MathFunctions" twice when you configure the build with -DUSE_MYMATH=ON. This is why you are getting "CMake Error at CMakeLists.txt:19 (add_subdirectory):"
To fix, remove
#add the MathFunctions Library
add_subdirectory(MathFunctions)
and rely on
if(USE_MYMATH)
add_subdirectory(MathFunctions)
list(APPEND EXTRA_LIBS MathFunctions)
list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
endif()
In your CMakeLists.txt file, you are doing
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
${EXTRA_LIBS}
)
Instead of
${EXTRA_LIBS}
It should be
${EXTRA_INCLUDES}
in Discourse Cmake Org -- help with tutorial step 2
Josef Angstenberger
jtxa said
The files in Step3 are the expected result if you do everything from Step2.
Can you please compare your files against the ones from Step3 to see if there are any relevant differences?
Blockquote
Marshallb's solution will solve nahesh relkar's problem
Loading Step2/CMakeLists.txt and Step3/CMakeLists.txt into vimdiff helped me to fix mine

How can i include SDL_gfx libraries in a Clion project?

So there is a weird thing that I've encountered, where i can make the SDL2 libraries work in clion but if i include the SDL_gfx libraries it won't compile.
So here is what I've done so far:
I've downloaded the Windows 64 version of SDL from the website, uncompressed it, and dragged the files in the corresponding MinGW folder.
I've edited the cmake file so that clion can see it as well, and it really works
My cmake file:
cmake_minimum_required(VERSION 3.15)
project(pontok C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
find_package(SDL2 REQUIRED)
add_executable(pontok main.c)
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_MIXER_INCLUDE_DIR}
)
target_link_libraries(pontok ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARY}
${SDL2_MIXER_LIBRARY}
)
I've downloaded the SDL_gfx package from here and put the .h and .a files in the corresponding MinGW folders. Clion can see it, and it appears normal until I hit compile:
If my code is:
#include <stdio.h>
#include <math.h>
#include <SDL2\SDL2_gfxPrimitives.h>
#include <SDL2\SDL.h>
const int SCREEN_WIDH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
SDL_Log("Nem indithato az SDL: %s", SDL_GetError());
exit(1);
}
SDL_Window *window = SDL_CreateWindow("SDL peldaprogram", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 440, 360, 0);
if (window == NULL) {
SDL_Log("Nem hozhato letre az ablak: %s", SDL_GetError());
exit(1);
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (renderer == NULL) {
SDL_Log("Nem hozhato letre a megjelenito: %s", SDL_GetError());
exit(1);
}
SDL_RenderClear(renderer);
int x, y, r;
//circleRGBA(renderer, x, y, r, 255, 0, 0, 255);
//circleRGBA(renderer, x + r, y, r, 0, 255, 0, 255);
//circleRGBA(renderer, x + r * cos(3.1415 / 3), y - r * sin(3.1415 / 3), r, 0, 0, 255, 255);
SDL_RenderPresent(renderer);
SDL_Event ev;
while (SDL_WaitEvent(&ev) && ev.type != SDL_QUIT) {
}
SDL_Quit();
return 0;
}
Than it works. It compiles and the blank window appears. But if i remove those three lines from comments, then it wont compile, and I'll get the next error:
CMakeFiles\pontok.dir/objects.a(main.c.obj): In function `SDL_main':
C:/Prog/pontok/main.c:28: undefined reference to `circleRGBA'
C:/Prog/pontok/main.c:29: undefined reference to `circleRGBA'
C:/Prog/pontok/main.c:30: undefined reference to `circleRGBA'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\pontok.dir\build.make:88: pontok.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/pontok.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/pontok.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: pontok] Error 2
The weird thing is that clion can see these circleRGBA unctions, in this picture we can see that it can recognize the function, it writes the attributes next to the variables.
Unfortunately SDL_gfx does not have a standard cmake module. But you can find one on the internet by googling for FindSDL2_gfx.cmake. Put this file in your cmake/Modules directory.
find_package(SDL2_gfx REQUIRED)
Then use ${SDL2_GFX_LIBRARIES} for linking
Ok so i figured it out. The problem was that clion could not see the .c SDL2_gfx files, so i had to add them to the project and had to edit the following line in the CMakeList.txt:
add_executable(pontok main.c SDL2_framerate.c SDL2_gfxPrimitives.c SDL2_imageFilter.c SDL2_rotozoom.c)
This way it compiled and worked properly.

Cmake passing arguments

I have a program to recognize files based on their signatures. Works great. But I'm new to C and am now trying to get an IDE called CLion to work. However, I can't figure out how to add command arguments to cmake - such that when I run main and want to pass a gifFile or a pdfFile to recognize I can do so. Here is my code so far for cmake.
cmake_minimum_required(VERSION 3.8)
project(Assignment6)
set(CMAKE_C_STANDARD 99)
set(SOURCE_FILES file_recognizer.c)
add_executable(Assignment6 ${SOURCE_FILES})
in the command line this would be something like
gcc file_recognizer.c -o Assignment6
and then you say
./Assignment6 gifFile.gif
How do I get cmake to accept the argument at the end, "gifFile.gif"?
Below is my main function for reference if needed
int main(int argc, char const *argv[]) {
FILE *yourFile;
unsigned char *fileBytes, *fileType;
long fileLength;
fileLength = 10;
if(argc != 2 || (yourFile = fopen(argv[1], "rb")) == NULL) {
printf("Invalid Input\n");
exit(-1);
}
fileBytes = readFile(yourFile, fileLength, fileBytes);
determineFileType(fileBytes, fileType);
return 0;
}
This isn't something CMake is designed to do. I mean, it's do-able with CMake:
add_custom_command(OUTPUT output COMMAND Assignment6 ARGS gifFile.gif)
But what it sounds like what you want to do isn't part of the build process and CMake is all about the building, testing, and packaging software, not running it.
Since you're using CLion, you might be better off setting the program arguements in CLion for debugging purposes.
Click here:
and enter your args here: