I recently made the switch from a PC to a Mac, Visual Studio to Netbeans, and Java to C++. I tried to include a boost library into my program, and when I build my code, I receive a build error. Can someone please walk me through what this build error is saying? I followed this post to add the libraries. I also followed this Boost getting start tutorial, and the Boost folder is in the "Netbeans Projects" folder, this is the directory "/Users/Nate/NetBeansProjects/boost_1_60_0/boost". Should the boost files have been placed somewhere else?
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/stockapp
mkdir -p dist/Debug/GNU-MacOSX
g++ -o dist/Debug/GNU-MacOSX/stockapp build/Debug/GNU-MacOSX/main.o -L../boost_1_60_0/boost -l boost
ld: library not found for -lboost
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/stockapp] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 213ms)
I am trying to build an program that will download website HTML and parse the HTML to retrieve stock prices from fiance.yahoo.com, here is the unfinished code:
using namespace std;
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <boost/asio.hpp> //code worked before adding this include
static string Index; //initialize string hosting Index Name
static vector<string> Symbol;
int ReadIndexFile()
{
string FileRead;
string FileName;
//string Temp;
int count = 0;
FileName = Index + "Symbols.csv";
cout << FileName << "\n";
ifstream source(FileName.c_str());//establishes source file
while (!source.eof()) //reads source until end of file
{
while (getline(source, FileRead, ','))//retrieves source data to ',' and stores in temp
{
Symbol.push_back(FileRead); //writes to array line by line
cout << Symbol.at(count);
count++;
}
}
}
int DownloadHTML()
{
cout << "HTML Downloaded";
}
int main(int argc, char** argv) {
cout << "Name your Index: ";
cin >> Index;
ReadIndexFile();
DownloadHTML();
return 0;
}
As you can clearly see in the error message that "Boost" library not found.
ld: library not found for -lboost
So you need to install it using the following command;
sudo apt-get install libboost-all-dev
Hope this helps.
Edit:
As MAC does not support apt-get so you need to use http://brew.sh/.
Please have a look in this url http://stackoverflow.com/questions/19688424/why-is-apt-get-function-not-working-in-terminal-on-mac-osx-10-9 for more details about how Homebrew.
Related
I am new to programming and have just installed this text editor on a friend's suggestion.
I don't know what went wrong but I get this error on building a simple C++ code.
#include <iostream>
using namespace std;
int main(){
int a;
cin>>a;
for(int i=0;i<a;i++)
cout<<"HEllo World!";
return 0;
}
The error is as follows:-
ld: can't write output file to '/Users/vihangawagholkar/Desktop/dsa/test' because that path is a directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 234ms with exit code 1]
[shell_cmd: g++ "/Users/vihangawagholkar/Desktop/dsa/test.cpp" -o "/Users/vihangawagholkar/Desktop/dsa/test" && "/Users/vihangawagholkar/Desktop/dsa/test"]
[dir: /Users/vihangawagholkar/Desktop/dsa]
[path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin]
I'm building the following code with cmake. I want to use tensorflow's C++ API,but I encountered errors when compiling the code.
Here are the errors:
>/home/zifeng/software/clion-2017.2.3/bin/cmake/bin/cmake --build
>/home/zifeng/CLionProjects/tfcpp_demo/cmake-build-debug --target all -- -j 4
>[ 50%] Building CXX object CMakeFiles/tfcpp_demo.dir/src/main.cpp.o
>[100%] Linking CXX executable tfcpp_demo
>/usr/bin/ld: CMakeFiles/tfcpp_demo.dir/src/main.cpp.o: undefined reference to symbol '_ZNK10tensorflow6Status8ToStringB5cxx11Ev'
>//home/zifeng/CLionProjects/tfcpp_demo/./lib/libtensorflow_framework.so: error adding symbols: DSO missing from command line
>collect2: error: ld returned 1 exit status
>CMakeFiles/tfcpp_demo.dir/build.make:94: recipe for target 'tfcpp_demo' failed
>make[2]: *** [tfcpp_demo] Error 1
>CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/tfcpp_demo.dir/all' failed
>make[1]: *** [CMakeFiles/tfcpp_demo.dir/all] Error 2
>Makefile:83: recipe for target 'all' failed
>make: *** [all] Error 2
Here is my code:
#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/public/session.h>
#include <iostream>
using namespace std;
using namespace tensorflow;
int main()
{
Session* session;
Status status = NewSession(SessionOptions(), &session);
if (!status.ok()) {
cout << status.ToString() << "\n";
return 1;
}
cout << "Session successfully created.\n";
}
Here is my makefile:
cmake_minimum_required(VERSION 3.7)
project(tfcpp_demo)
set(CMAKE_CXX_STANDARD 11)
link_directories(./lib)
set(SOURCE_FILES
src/main.cpp)
include_directories(
/home/zifeng/software/tensorflow/tensorflow
/home/zifeng/software/tensorflow/tensorflow/bazel-genfiles
/home/zifeng/software/tensorflow/tensorflow/tensorflow/contrib/makefile/gen/protobuf/include
/home/zifeng/software/tensorflow/tensorflow/tensorflow/contrib/makefile/downloads/nsync/public
/usr/local/lib/python2.7/dist-packages/tensorflow/include
)
add_executable(tfcpp_demo ${SOURCE_FILES})
target_link_libraries(tfcpp_demo tensorflow_cc)
I have same problem with you and I fix it.
It looks some libtensorflow .so files are missing at linking.
I generate my libtensorflow_cc.so by using two command:
bazel build --config=monolithic --config=cuda //tensorflow:libtensorflow_cc.so
bazel build --config=monolithic --config=cuda //tensorflow:libtensorflow_framework.so
It is better than one command.
bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so
#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/public/session.h>
#include <iostream>
using namespace std;
using namespace tensorflow;
int main()
{
Session* session;
Status status = NewSession(SessionOptions(), &session);
if (!status.ok()) {
cout << status.ToString() << "\n";
return 1;
}
cout << "Session successfully created.\n";
}
A while ago I installed MingW to learn C++ with NetBeans, but until now I didn't find the time. Now I created a new C++ project, made a Hello World program with std::cout and it worked immediately. Then I tried to write a file, but it failed:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv) {
cout << "test" << endl;
fstream f;
f.open("a.txt", fstream::in | fstream::out | fstream::trunc);
f << "out" << endl;
f.close();
return 0;
}
lumosc (Build, run):
cd 'D:\<My name>\Programmierung\NetBeans Projects\lumosc_1\lumosc'
D:\Programme\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/D/Programme/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
"/D/Programme/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_1-Windows/lumosc.exe
make.exe[2]: Entering directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
mkdir -p build/Debug/MinGW_1-Windows
rm -f "build/Debug/MinGW_1-Windows/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/MinGW_1-Windows/main.o.d" -o build/Debug/MinGW_1-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW_1-Windows
g++ -o dist/Debug/MinGW_1-Windows/lumosc build/Debug/MinGW_1-Windows/main.o
make.exe[2]: Leaving directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
make.exe[1]: Leaving directory `/d/<My name>/Programmierung/NetBeans Projects/lumosc_1/lumosc'
Output (Note that cout << "test" << endl; wasn't executed):
RUN FAILED (exit value -1.073.741.511, total time: 64ms)
I didn't see any error message. However, when I started the newly created lumosc.exe manually, the following window popped up:
(Translated: Entry point not found - The procedure entry point "__gxx_personality_v0" was not found in the "libstdc++-6.dll" DLL.)
Here's some information about my MingW installation:
I'm completely new to this topic and I hope somebody can help me out!
I am using CGAL and I have this minimal example (which should be fine since it's an example):
#include <iostream>
#include <vector>
#include <CGAL/Cartesian_d.h>
#include <CGAL/point_generators_d.h>
typedef CGAL::Cartesian_d<double> Kd;
typedef Kd::Point_d Point;
typedef CGAL::Creator_uniform_d<std::vector<double>::iterator, Point>Creator_d;
int main ()
{
int nb_points = 10;
int dim =5;
double size = 100.0;
std::cout << "Generating "<<nb_points<<" random points in a"
<<" ball in "<<dim<<"D of center 0 and radius "<<size<<std::endl;
std::vector<Point> v;
v.reserve (nb_points);
CGAL::Random_points_in_ball_d<Point> gen (dim, 100.0);
for (int i = 0; i < nb_points; ++i) v.push_back (*gen++);
for (int i = 0; i < nb_points; ++i) std::cout<<" "<<v[i]<<std::endl;
return 0;
}
However, I am getting this error:
samaras#samaras-A15:~/code/random_generator$ make
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
make[2]: *** No rule to make target `/usr/lib/i386-linux-gnu/libmpfr.so', needed by `main'. Stop.
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
What I should do?
I am creating the CmakeLists files like this:
~/code/CGAL-4.3/scripts/cgal_create_CMakeLists
cmake -DCGAL_DIR=$HOME/code/CGAL-4.3 .
as I describe here.
If you need more information, please let me know.
--
cd /usr/lib/i386-linux-gnu/libmpfr.so
bash: cd: /usr/lib/i386-linux-gnu/libmpfr.so: No such file or directory
The easiest way to install CGAL on Debian or Ubuntu is apt-get install libcgal-dev (or libcgal-qt4-dev). If you are going to build CGAL yourself, you should still apt-get build-dep cgal which installs the most relevant dependencies.
The library was missing after all, so I did this and we are OK:
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg
Source
I've got the following code in C++
if (should_run_make) {
std::string make = "make -C ";
make.append(outdir);
std::cout << "Make cmd is " << make << std::endl;
system(make.c_str());
}
This reports the following:
Make cmd is make -C /home/hamiltont/temp/ make: Entering directory
/home/hamiltont/temp' make: *** No targets. Stop.
make: Leaving directory/home/hamiltont/temp'
However, doing it manually works fine in multiple ways e.g.
[hamiltont#4 generator]$ make -C /home/hamiltont/temp/
make: Entering directory `/home/hamiltont/temp'
g++ -O3 -I/usr/include/openmpi-x86_64 -L/usr/local/lib -L/usr/lib64/openmpi/lib -lmpi -lmpi_cxx -lboost_serialization -lboost_mpi stg_impl.cpp -o impl
make: Leaving directory `/home/hamiltont/temp'
[hamiltont#4 generator]$ cd /home/hamiltont/temp/
[hamiltont#4 temp]$ make
g++ -O3 -I/usr/include/openmpi-x86_64 -L/usr/local/lib -L/usr/lib64/openmpi/lib -lmpi -lmpi_cxx -lboost_serialization -lboost_mpi stg_impl.cpp -o impl
Are you generating the makefile from within your C program? That's the only reason I could imagine would cause that specific error message.
make: *** No targets. Stop.
Reproducing the error
Here's how I could generate that message:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("Makefile", "w");
fputs("all:\n\techo Done.\n", fp);
system("make");
fclose(fp);
return 0;
}
This, predictably, prints:
make: *** No targets. Stop.
I say predictably because Makefile will be empty! This is because IO is buffered...
Fixed version
So, I close the file before calling system(), which flushes the buffer (fflush() would also do the trick):
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("Makefile", "w");
fputs("all:\n\techo Done.\n", fp);
fclose(fp);
system("make");
return 0;
}
Output:
echo Done.
Done.
I used C's IO functions for clarity, but the same rules apply to <iostream>.