0

So, I've searched all around the web and I couldn't find anything.

I'm started with python, and I made a TKinter application. At first, I tried to compile it to an .exe file, but that didn't work. So now I'm embedding python in C++. Every single time I try to compile it (using Dev-C++), I get the error:

C:\Users\*****\AppData\Local\Temp\ccsqSJ5V.o    [program-name].cpp:(.text+0x10): undefined reference to `__imp_Py_Initialize'
C:\Users\*****\AppData\Local\Temp\ccsqSJ5V.o    [program-name].cpp:(.text+0x25): undefined reference to `__imp_PyRun_SimpleStringFlags'
C:\Users\*****\AppData\Local\Temp\ccsqSJ5V.o    [program-name].cpp:(.text+0x2e): undefined reference to `__imp_Py_Finalize'
F:\Documents\Videos\[program-name]\program\collect2.exe [Error] ld returned 1 exit status

F: stands for the flash drive. In the Dev-c++ options, I added:

-Wall -I\C:\Users\*****\AppData\Local\Programs\Python\Python35\include

So this is the full command:

g++.exe "F:\Documents\Videos\[program-name]\program\[program-name].cpp" -o "F:\Documents\Videos\[program-name]\program\[program-name].exe" -Wall -I\C:\Users\*****\AppData\Local\Programs\Python\Python35\include -I"C:\Programma's\Dev-C++\MinGW64\include" -I"C:\Programma's\Dev-C++\MinGW64\x86_64-w64-mingw32\include" -I"C:\Programma's\Dev-C++\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Programma's\Dev-C++\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -I"C:\Users\*****\AppData\Local\Programs\Python\Python35\include" -L"C:\Programma's\Dev-C++\MinGW64\lib" -L"C:\Programma's\Dev-C++\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc

My question is: how do I deal with this?

And please note: I haven't got administrator privileges, I'm just a standard user.


Python version: 3.5.1
Dev-C++ version: 5.11
GCC version: I don't know, but I'll find it out if needed :)

EDIT: Because of the duplicate mark by NathanOliver, I'll ask it like this: which command line variables do I have to add to compile it?

TooMuchRAM
  • 103
  • 6
  • The duplicate question, although more generic for any missing symbols, won't help people around the internet, not proeficient in C/C++, trying to build Python extensions with "dev c++"- One single, short answer with the correct command line parameters pointing to the proper Python library would be a far more useful internet resource here than a "closed as duplicate". – jsbueno Jun 21 '16 at 13:26
  • @jsbueno In the past, I programmed a bit in C, but I stopped cause I didn't understand. But, agree. And Dev-C++ is just the C/C++ editor I'm working in. It just has a build-in compiler feature, using GCC. – TooMuchRAM Jun 21 '16 at 13:37

1 Answers1

1

The linker is complaining bacause it can't find a group of references about some python stuff, as a matter of fact I don't see any python library in the g++ invocation.

You need to had something like this -lpython3.5.1 to tell g++ to link against the python library (assuming python is installed in your system, else you will have to add the path to the library using the -L option).

More resources on g++ makefiles and linking: https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

Robbykk
  • 66
  • 6
  • I've installed python locally, but -lpython3.5.1 returns `No such file or directory`. I tried: `-L"C:\Users\*****\Local\Programs\Python\Python35`, `-l"C:\Users\*****\Local\Programs\Python\Python35`,`-L"C:\Users\*****\Local\Programs\Python\Python35\include`, `-l"C:\Users\*****\Local\Programs\Python\Python35\include` AND all of above without quotes. None of it worked. – TooMuchRAM Jun 21 '16 at 17:25
  • It's very simple: The -L option has to point to the library path, the -I (it's an i) to the headers path. Then you add the library name -lLibraryName. How did you install python? I would start by locating the library in your system. The error you showed on start is the linker telling you that you forgot to tell him about the python library. The "No such file or directory" means that the path you told him is wrong. – Robbykk Jun 22 '16 at 04:13
  • I installed Python via the offline installer, in `%appdata%\Programs\Python\Python35`. – TooMuchRAM Jul 09 '16 at 18:49
  • You should have a folder called Lib inside the Python folder. You have to pass to -L the path to the python library. You passed to -L this: -L"C:\Users\*****\Local\Programs\Pyt‌​hon\Python35\include while you should have passed something like: -L"C:\Users\*****\Local\Programs\Pyt‌​hon\Python35\Lib (include is typically the folder of the headers while lib the folder for the libraries) – Robbykk Jul 09 '16 at 19:29