Why qt class can't be combined with some C++ source code
-
I am developing some features on some open-source projects, but I observe that open source code can be compiled successfully with g++ and cmake....
but when i import cmake project and it can compile successfully in qt....
my problom is where that i want to add some layers that use qt classed i faced with too many strange errors.....
for special case for srsran project when I used this section i have too many erros....How can overcome this problem in qt? This is only one problem but altogether Qt with other source cpp i faced with too many strange errors....can anyone guide me? Thanks in advance
cmake section
######Custom CMake setction for creating GUI ENB set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) #set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # modify the actual value of the current directory's `COMPILE_OPTIONS` (copy from above line remains unchanged). subdirectories inherit a copy of their parent's `COMPILE_OPTIONS` at the time the subdirectory is processed. add_compile_options(-Wno-error) find_package(Qt5 COMPONENTS Widgets REQUIRED ) add_executable(LTEeNB #main.cc main.cpp enb_layer.cpp enb_layer.h mainwindow.cpp mainwindow.h mainwindow.ui config_enb_layer.h enb_helper_functions.h enbthread.cpp enbthread.h ../enb.cc ../metrics_stdout.cc ../metrics_csv.cc ../metrics_json.cc ../metrics_e2.cc #../enb_cfg_parser.cc ) target_link_libraries(LTEeNB PRIVATE ${SRSENB_SOURCES} ${SRSRAN_SOURCES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${SEC_LIBRARIES} ${LIBCONFIGPP_LIBRARIES} ${SCTP_LIBRARIES} enb_cfg_parser srsran_common srsgnb_rrc_config_utils ${LIBCONFIGPP_LIBRARIES} Qt5::Widgets )Source Code
#include <poll.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <unistd.h> #include "srsran/common/common_helper.h" #include "srsran/common/config_file.h" #include "srsran/common/crash_handler.h" #include "srsran/common/tsan_options.h" #include "srsran/srslog/event_trace.h" #include "srsran/srslog/srslog.h" #include "srsran/support/emergency_handlers.h" #include "srsran/support/signal_handler.h" #include <boost/program_options.hpp> #include <boost/program_options/parsers.hpp> #include <iostream> #include <memory> #include <srsran/common/string_helpers.h> #include <string> #include "srsenb/hdr/enb.h" #include "srsenb/hdr/metrics_csv.h" #include "srsenb/hdr/metrics_e2.h" #include "srsenb/hdr/metrics_json.h" #include "srsenb/hdr/metrics_stdout.h" #include "srsran/common/enb_events.h" class enb_layer { //Q_OBJECT public: //public:public: enb_layer(); ~enb_layer(); int start(int argc, char* argv[]); void stop(); };Error:
/...../lib/include/srsran/asn1/e2sm_kpm_v2.h:56: error: expected ‘}’ before ‘::’ token 56 | #define None std::numeric_limits<uint32_t>::max() | ^~ -
Hi @stackprogramer,
It looks to me like the compiler is interpreting the code in
e2sm_kpm_v2.has (plane old) C, and not C++. This is probably because one of your*.ccfiles is including the header (either directly, or indirectly), and CMake is (again, probably) assuming your*.ccfiles are C (not C++).You could rename all
*.ccfiles to*.cpp, or tell CMake some other way that they're all C++.Or if you really do need to mix C and C++ code, you will need to ensure that the C and C++ headers are also separated - eg consider using a
*.hppextension for the C++ headers.Hope that helps point you in the right direction.
Cheers.
-
Hi @stackprogramer,
It looks to me like the compiler is interpreting the code in
e2sm_kpm_v2.has (plane old) C, and not C++. This is probably because one of your*.ccfiles is including the header (either directly, or indirectly), and CMake is (again, probably) assuming your*.ccfiles are C (not C++).You could rename all
*.ccfiles to*.cpp, or tell CMake some other way that they're all C++.Or if you really do need to mix C and C++ code, you will need to ensure that the C and C++ headers are also separated - eg consider using a
*.hppextension for the C++ headers.Hope that helps point you in the right direction.
Cheers.
@Paul-Colby
But new question how can mix c and cpp code that we have not any problems.....when i change header file in cpp to hpp we have problems and errors yet..... -
@Paul-Colby
But new question how can mix c and cpp code that we have not any problems.....when i change header file in cpp to hpp we have problems and errors yet.....@stackprogramer
Maybe you need to use extern "C"
https://stackoverflow.com/questions/12066279/using-c-libraries-for-c-programs -
@stackprogramer
Maybe you need to use extern "C"
https://stackoverflow.com/questions/12066279/using-c-libraries-for-c-programs@mpergand @Paul-Colby Thanks very much,Finally my problem is solved. I defined a pure cpp layer call c function in it and ...i used this layer in other qt classes...
-
S stackprogramer has marked this topic as solved on