i have included the path to python.h(C:\Users\vinay\AppData\Local\Programs\Python\Python37-32\include) file and gave the library path of the project to "C:\Users\AppData\Local\Programs\Python\Python37-32\Lib"
and my code is as pasted below:-
#include <iostream>
#include <Python.h>
using namespace std;
int main(int argc, char **argv)
{
PyObject *pInt;
Py_Initialize();
PyRun_SimpleString("print('Hello world from embedded python!!!\n')");
Py_Finalize();
cout<<"now i am finally out of the python"<<endl;
return 0;
}
when i compile the program there is no error but when i build the project i get the following erros
C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:8: undefined reference to `_imp__Py_Initialize'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:9: undefined reference to `_imp__PyRun_SimpleStringFlags'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:10: undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Cpp_in_python] Error 1
mingw32-make.exe: *** [All] Error 2
Cpp_in_python.mk:78: recipe for target 'Debug/Cpp_in_python' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/vinay/Documents/CppWorkspace/Cpp_in_python'
Makefile:4: recipe for target 'All' failed
====4 errors, 0 warnings====
Related
I want to start with multithreading, but my clion IDE (v. 2019.3.6) does not recognize created threads.
I also try to use threads from boost library, but there is also common error ("undefined reference to boost::threads" is there). I use c++14 in my clion and mingw compilator.
I compiled boost library using g++.
Code I try to run:
#include <iostream> // std::cout
#include <boost/thread.hpp>
void foo(){
// do stuff...
}
void bar(int x){
// do stuff...
}
int main(){
boost::thread t1(bar, 1);
t1.join();
return 0;
}
or:
#include <iostream> // std::cout
#include <thread>
void foo(){
// do stuff...
}
void bar(int x){
// do stuff...
}
int main(){
std::thread t1(bar, 1);
t1.join();
return 0;
}
errors which it generates:
CMakeFiles\client.dir/objects.a(client.cpp.obj): In function `boost::thread::start_thread()':
C:/boost_builded_from_sources/include/boost/thread/detail/thread.hpp:182: undefined reference to `boost::thread::start_thread_noexcept()'
CMakeFiles\client.dir/objects.a(client.cpp.obj): In function `boost::thread::~thread()':
C:/boost_builded_from_sources/include/boost/thread/detail/thread.hpp:257: undefined reference to `boost::thread::detach()'
CMakeFiles\client.dir/objects.a(client.cpp.obj): In function `boost::thread::join()':
C:/boost_builded_from_sources/include/boost/thread/detail/thread.hpp:759: undefined reference to `boost::thread::get_id() const'
C:/boost_builded_from_sources/include/boost/thread/detail/thread.hpp:759: undefined reference to `boost::this_thread::get_id()'
C:/boost_builded_from_sources/include/boost/thread/detail/thread.hpp:762: undefined reference to `boost::thread::join_noexcept()'
CMakeFiles\client.dir/objects.a(client.cpp.obj): In function `boost::detail::thread_data<boost::_bi::bind_t<void, void (*)(int), boost::_bi::list1<boost::_bi::value<int> > > >::~thread_data()':
C:/boost_builded_from_sources/include/boost/thread/detail/thread.hpp:94: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
CMakeFiles\client.dir/objects.a(client.cpp.obj):client.cpp:(.rdata$.refptr._ZTVN5boost6detail16thread_data_baseE[.refptr._ZTVN5boost6detail16thread_data_baseE]+0x0): undefined reference to `vtable for boost::detail::thread_data_base'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\client.dir\build.make:86: client.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/client.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/client.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: client] Error 2
or errors thread from std::thread
C:\Users\Admin\Desktop\client\client.cpp: In function 'int main()':
C:\Users\Admin\Desktop\client\client.cpp:15:10: error: 'thread' is not a member of 'std'
std::thread t1(bar, 1);
^~~~~~
C:\Users\Admin\Desktop\client\client.cpp:15:10: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
C:\Users\Admin\Desktop\client\client.cpp:5:1:
+#include <thread>
C:\Users\Admin\Desktop\client\client.cpp:15:10:
std::thread t1(bar, 1);
^~~~~~
C:\Users\Admin\Desktop\client\client.cpp:16:5: error: 't1' was not declared in this scope
t1.join();
^~
C:\Users\Admin\Desktop\client\client.cpp:16:5: note: suggested alternative: 'tm'
t1.join();
^~
tm
mingw32-make.exe[3]: *** [CMakeFiles\client.dir\build.make:63: CMakeFiles/client.dir/client.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/client.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/client.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: client] Error 2
Why thread is not memeber of std::thread?
I have attached proper header
Is this possible that mingw does not support multithreading?
Maybe someone had problem like this and will be able to help.
The mingw didn't recognize thread library.
I changed version of compilator to another and everything works nice.
I successfully built tensorflow_cc on Ubuntu 16.04 with a static build.
I was testing a small code I took from tflite guide:
$> cat test1.cpp
#include <cstdio>
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
using namespace tflite;
int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "minimal \n");
return 1;
}
const char* filename = argv[1];
std::unique_ptrtflite::FlatBufferModel model =
tflite::FlatBufferModel::BuildFromFile(filename);
return 0;
}
I am getting this error:
[ 50%] Building CXX object CMakeFiles/example.dir/example.cpp.o
[100%] Linking CXX executable example
CMakeFiles/example.dir/example.cpp.o: In function main': example.cpp:(.text+0x57):
undefined reference to tflite::DefaultErrorReporter()'
example.cpp:(.text+0x6d): undefined reference to
tflite::FlatBufferModel::BuildFromFile(char const*, tflite::ErrorReporter*)'
CMakeFiles/example.dir/example.cpp.o: In function
std::default_deletetflite::FlatBufferModel::operator()(tflite::FlatBufferModel*) const':
example.cpp
(.text.ZNKSt14default_deleteIN6tflite15Flat
BufferModelEEclEPS1[ZNKSt14default_deleteIN6tflite15FlatBufferModelEEclEPS1]+0x1e):
undefined reference to `tflite::FlatBufferModel::~FlatBufferModel()'
collect2: error: ld returned 1 exit status
CMakeFiles/example.dir/build.make:85: recipe for target 'example' failed
make[2]: *** [example] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/example.dir/all' failed
make[1]: *** [CMakeFiles/example.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Any suggestions on how to proceed?
It's answered on https://github.com/tensorflow/tensorflow/issues/36661
By some strange reason, you need to provide your object file first than tflite library to your linker.
FYI https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking
I'm having this problem when I'm trying to start my computer camera.
I'm using this code
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv2/videoio.hpp"
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
}
and it shows this error
enter code here
make all
Building target: video
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "video" ./yes.o -lopencv_video
./yes.o: In function `main':
/home/allofthepower/eclipse-workspace/video/Debug/../yes.cpp:10: undefined reference to `cv::VideoCapture::VideoCapture(int)'
makefile:44: recipe for target 'video' failed
/home/allofthepower/eclipse-workspace/video/Debug/../yes.cpp:10: undefined reference to `cv::VideoCapture::~VideoCapture()'
collect2: error: ld returned 1 exit status
make: *** [video] Error 1
I'm new to Ubuntu and OpenCV, please help.
In my case I could fix this by adding -lopencv_videoio to the g++ compiler.
I've tried the code on Codeblocks and Clion and I'm still getting a redefinition of struct tm error.
#include <iostream>
#include <ctime> // Needed for the true randomization
#include <cstdlib>
using namespace std;
int main ()
{
int xRan;
srand( time(0)); // This will ensure a really randomized number by help of time.
xRan=rand()%15+1; // Randomizing the number between 1-15.
cout << "Shows a random number between 1-15: " << xRan;
return 0;
}
When ever I use the library I get the error. Not sure if theres something
buggy in the minigw include folder or what. Would deleting all my ide's and reinstalling help? Any ideas maybe why?
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ctime:42:0,
from C:\Users\Kelvindavis\CLionProjects\untitled\main.cpp:2:
c:\mingw\include\time.h:172:8: error: redefinition of 'struct tm'
struct tm
^
In file included from
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar:44:0,
from
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\postypes.h:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38from
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39from
C:\Users\Kelvindavis\CLionProjects\untitled\main.cpp:1:
c:\mingw\include\wchar.h:87:8: error: previous definition of 'struct tm'
struct tm {
^
mingw32-make.exe[3]: * [CMakeFiles/untitled.dir/main.cpp.obj] Error 1
CMakeFiles\untitled.dir\build.make:61: recipe for target
'CMakeFiles/untitled.dir/main.cpp.obj' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/untitled.dir/all'
failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/untitled.dir/rule'
failed
mingw32-make.exe[2]: [CMakeFiles/untitled.dir/all] Error 2
mingw32-make.exe[1]: [CMakeFiles/untitled.dir/rule] Error 2
mingw32-make.exe: * [untitled] Error 2
Makefile:117: recipe for target 'untitled' failed
i tryng to build a small example of Xerces with xerces c++ 3.1 and cmake, but i and only getting linkings problems.
This is my cmkelists.txt:
//============================================================================
project(ConfiguradorXerces)
cmake_minimum_required(VERSION 2.8)
include_directories (/home/ricardo/Desktop/librerias/xerces/xerces-c-3.1.1/src)
link_directories (/home/ricardo/Desktop/librerias/xerces/xerces-c-3.1.1/src/.libs)
link_directories (/home/ricardo/Desktop/librerias/xerces/xerces-c-3.1.1/src/)
set ( XercesLib xerces-c )
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${XercesLib})
//==============================================
//===============================================
#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
using namespace xercesc;
using namespace std;
int main()
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
// Do your failure processing here
return 1;
}
// Do your actual work with Xerces-C++ here.
XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
//==============================================
and this is my console output:
CMakeFiles/ConfiguradorXerces.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x25): undefined reference to `xercesc_3_1::XMLUni::fgXercescDefaultLocale'
main.cpp:(.text+0x2a): undefined reference to `xercesc_3_1::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_1::PanicHandler*, xercesc_3_1::MemoryManager*)'
main.cpp:(.text+0x2f): undefined reference to `xercesc_3_1::XMLPlatformUtils::Terminate()'
CMakeFiles/ConfiguradorXerces.dir/main.cpp.o:(.gcc_except_table+0x10): undefined reference to `typeinfo for xercesc_3_1::XMLException'
collect2: error: ld returned 1 exit status
make[2]: *** [ConfiguradorXerces] Error 1
make[1]: *** [CMakeFiles/ConfiguradorXerces.dir/all] Error 2
make: *** [all] Error 2
16:28:55: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project ConfiguradorXerces (target: Desktop)
When executing step 'Make'
//
i was thinking trhat my cmakeLsits.txt was not complete, there is an especial setup that it has to be done??
thx in advance
I am pretty sure that target_link_libraries() macro accepts a target as its first parameter:
target_link_libraries(<target> [item1 [item2 [...]]]
[[debug|optimized|general] <item>] ...)
And you have forgot to specify it. So instead of target_link_libraries(${XercesLib}), try target_link_libraries(${PROJECT_NAME} ${XercesLib}).
Hopefully, that solves it.