Trouble compiling Tensorflow in c++/Eclipse - c++

I have trouble getting Tensorflow to work in my c++ environment: Eclipse.
I git cloned tensorflow, built with bazel, and installed the resulting pip-package exactly like described here:
https://www.tensorflow.org/versions/r0.7/get_started/os_setup.html#installing-from-sources
I created a new c++ project in Eclipse and added the /home/tensorflow to the include paths. However, when I try to build a simple "hello world" project with a few includes from TF I run into this error:
23:05:39 **** Incremental Build of configuration Debug for project cat_face ****
Info: Internal Builder is used for build
g++ -I/home/name/tensorflow -O0 -g3 -Wall -c -fmessage-length=0 -o src/cat_face.o ../src/cat_face.cpp
In file included from ../src/cat_face.cpp:2:0:
/home/name/tensorflow/tensorflow/core/public/session.h:22:48: fatal error: tensorflow/core/framework/graph.pb.h: No such file or directory
#include "tensorflow/core/framework/graph.pb.h"
^
compilation terminated.
23:05:39 Build Finished (took 186ms)
It seems to look for a file, which doesn't exist in the Tensorflow directory. Why is it looking for something that doesn't exist? I checked it out and the file really isn't there, even though I followed all steps.
My program was very simple:
#include <iostream>
#include "/tensorflow/core/public/session.h"
#include "/tensorflow/core/platform/env.h"
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
}
Where could this have gone wrong?

I think you are supposed to use bazel instead of cmake and make to build you project.
From what I know graph.pb.h is created by bazel during the build process.
Someone else had a similar problem: https://github.com/tensorflow/tensorflow/issues/1890

Related

Add SFML (third party library) to C++ project on Xcode

I'm learning how to build a simple UI in C++ on my Mac (OS 11.6) using Xcode.
As first step I'm compiling the "Hello world" program, my problem is that the build on Xcode fails but write my own command from terminal, instead, works.
This is the program, I'm using SFML :
#include <iostream>
#include "SFML/Graphics.hpp"
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
I have no error here but when launching Run from Xcode this is the output, in Graphics.hpp file :
#include <SFML/Window.hpp>. //'SFML/Window.hpp' file not found
#include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/CircleShape.hpp
//other header files
This is how the project is structured ("TestGui" is the project name) :
-TestGui.xcodeproj
-TestGui(folder)
--SFML(directory with all headers file available
-- main.cpp
SFML source code here
So I tried to compile it with my own hands from terminal with :
g++ main.cpp -I ./SFML -o main
and
clang++ main.cpp -I ./SFML -o main
In both cases it compiled, also run worked.
Since the error is linked to a file not found I tried to tell it where libraries are located, so in Xcode from Product->Scheme->Edit Scheme->Run->Arguments->Arguments passed on launch : added -I ./SFML. But the error is still alive.
Added SFML folder to targets from Xcode, didn't copy-pasted but maybe I did it wrong, this is my first time.
EDIT : SFML folder:
--SFML
--- many .hpp files
--- 5 folders (Audio, Graphic, Network, System and Window)
I tried to add also this argument : -L ./SFML but nothing.

"undefined reference to `WinMain#16'" Error in gcc editor

I am just learning c++ and began to watch a youtube tutorial by thenewboston. Unfortunately he is using Code::Blocks while I am using gcc and I do not have the option to create new class files with a button click and so had to manually create them.
I dont understand why the same code in Code::Blocks and gcc will work in Code::Blocks but not gcc. Does gcc require different coding for the same language?
EDIT: I have downloaded and tested in Code::Blocks myself
Other questions talk of how I need to give windows an entry point, but I dont know how to do that.
Test.cpp Code:
#include <iostream>
#include "ClassTest.h"
using namespace std;
int main() {
ClassTest bo;
}
ClassTest.h Code:
#ifndef CLASSTEST_H
#define CLASSTEST_H
class ClassTest {
public:
ClassTest();
};
#endif // CLASSTEST_H
ClassTest.cpp Code:
#include <iostream>
#include "ClassTest.h"
using namespace std;
ClassTest::ClassTest() {
cout << "blah blah" << endl;
}
I'm not quite sure I understand what the question is; I'm going to take it as "how do I get these three files to build into a .exe that I can run from the Windows commmand line?"
The answer is to run something like this on the command line, in the folder with the files:
g++ -c Test.cpp -o Test.o
g++ -c ClassTest.cpp -o ClassTest.o
g++ Test.o ClassTest.o -o Test.exe
The first two commands build each CPP file into an "object file", which isn't a whole program by itself but which contains the compiled version of the code in that CPP file. The last command tells the compiler to paste together the two object files into a program, and resolve all the cross-references between them. (For example, the part where Test.cpp constructs a ClassTest object needs to end up calling the ClassTest constructor code from ClassTest.cpp.)
Code::Blocks is an IDE and works out how to build each source file in your project and link them together by itself. But if you aren't using an IDE, you need to do that in another way. You can either do it manually like this, or you can write a Makefile that will check which code files have changed and rebuild and re-link everything that depends on them when you run the make command, which is how most people do it.
As for "giving Windows an entry point", that probably refers to GUI applications that want to display windows on the screen. For console programs like the one you have written, the "entry point" is main(), and you just print stuff to the command line window. To make actual Windows-style GUI windows of your own, you need to use the Windows API, which I can't tell you much about.

Cannot run Hello World C++ program

I am just starting C++ and downloaded a compiler and an IDE, both eclipse, and tried to make my first C++ program. I use the Hello World C++ Makefile Project, and add the all the stuff on the next page. I then build the program, and the build says this:
12:30:00 **** Build of configuration Default for project HelloWorld! **** make all Cannot run program "make": Launching failed
Error: Program "make" not found in PATH PATH=[C:/Program Files
(x86)/Java/jre1.8.0_91/bin/client;C:/Program Files
(x86)/Java/jre1.8.0_91/bin;C:/Program Files
(x86)/Java/jre1.8.0_91/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Program
Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files
(x86)\Common Files\Microsoft Shared\Windows
Live;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\Program
Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files
(x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files
(x86)\Common Files\Roxio Shared\12.0\DLLShared\;C:\Program Files
(x86)\Windows Live\Shared;c:\Program Files (x86)\Microsoft SQL
Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL
Server\100\DTS\Binn\;C:\Users\Jen\Desktop\eclipse;] 12:30:00 Build
Finished (took 122ms)***
I run the program, and it says:
Launch failed. Binary not found.
This is the code for the program:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("Hello World!");
return EXIT_SUCCESS;
}
There are two errors, too:
Function "puts" couldn't be resolved.
Symbol "EXIT_SUCCESS" couldn't be resolved.
Thanks in advance!
Nate N.
/////////////////////////////////////////////////////////////////////////
I followed the advise of user4581301 and the code now says this:
#include <iostream>
using namespace std;
int main() {
cout << "Hi World" << endl; // prints Hi World
return 0;
}
The build looks like this:
13:22:26 **** Rebuild of configuration Debug for project HiWorld ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\HiWorld.o" "..\src\HiWorld.cpp"
g++ -o HiWorld.exe "src\HiWorld.o"
13:22:27 Build Finished (took 835ms)
But now the program, although it does run, doesn't print anything.
Thanks in advance,
Nate N.
Launch failed. Binary not found.
well this is shown because you have 2 errors.
any error means = no binary compiled/linked
no binary compiled/linked = cant launch something which doesnt exist
solution = fixing the errors
#include #include
^ also this is not valid
Cannot run program "make": Launching failed Error: Program "make" not found in PATH
Kaboom! No make, no build, no binary to run.
Some compilers don't ship with Make out of the box, but I don't see any signs of a compiler toolchain in your path at all.
Eclipse is an IDE with support for a wide variety of different compilers. as a result it does not ship with one. Since the error message shows you are building on Windows, your simplest option is one of the many MinGW variants. And Since you are just starting, I recommend starting off with the plain-vanilla MinGW as Eclipse requires next to no extra configuration to use it.
Just make sure you follow the instructions to install msys along with MinGW to get make.

MingW environment paths

I am trying to compile a simple program but the MingW C++ compiler cannot find the path. I have two files one is C:\main.cpp the other one is C:\Include\test.h
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
cout << "test" << endl;
getchar();
return 0;
}
I have modified the CPATH, CPLUS_INCLUDE_PATH enviroment vars to include the C:\Include path but it still will not compile with g++ c:\main.cpp -o c:\main.exe
Output from command line.
c:\main.cpp:2:18: fatal error: test.h: No such file or directory
compilation terminated.
Also I used this registry file. Still doesn't work.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"
There's not really enough information here, and storing source files in the root is suspect, but you might try:
g++ -I Include c:\main.cpp -o c:\main.exe
Assuming your cwd is C:\
This plus system restart was needed.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"

-m32 flag not working to build 32 bit application

I am trying to compile some super simple code in Code::Blocks using GCC 4.4. I am on OS X Mavericks if that matters. I'm trying to compile and make a 32 bit executable, so I've taken the advice of a bunch of stack overflow posts to add the -m32 flag to the compiler (in Code::Blocks, I did Project > Build Options > Compiler Settings > Other Options > added -m32).
The code is the standard hello world program that pops up in every main file. I'll post it here for those who aren't familiar with Code::Blocks.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
When I go to build, I clean all the object files and rebuild, and I get the following warning which prevents an executable from being created:
||warning: ignoring file obj/Release/main.o, file was built for i386 which is not the architecture being linked (x86_64): obj/Release/main.o|
I'm not really sure where to go from here. I thought the -m32 flag deals with these things.
Any ideas or directions I can take? If there's any info I left out let me know.