Problems when installing cppflow - c++

I am trying to use the c++ wrapper for tensorflow api from https://github.com/serizba/cppflow.
I have copied the git repository. Downloaded the tensorflow api files (copied them into the cppflow folder), when I build the project in the folder, and then tries to run it from the project file created I get 37 errors, all related to Model.obj and Tensor.obj.
LNK2019 unresolved external symbol __imp_TF_NewStatus referenced in function "public: __cdecl Model::Model(class std::basic_string,class std::allocator > const &)" (??0Model##QEAA#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) example *\cppflow\examples\load_model\build\Model.obj 1
I am running it on Windows 10, with a c++ 17 compiler.
The CMakeFiles contain the following lines:
cmake_minimum_required(VERSION 3.10)
project(example)
set(CMAKE_CXX_STANDARD 17)
add_executable(example main.cpp ../../src/Model.cpp ../../src/Tensor.cpp)
target_include_directories(example PRIVATE ../../include)
target_link_libraries (example -ltensorflow)
I am trying to run a example from the github repo.
#include "../../include/Model.h"
#include "../../include/Tensor.h"
#include <numeric>
#include <iomanip>
int main() {
Model model("../model.pb");
model.init();
auto input_a = new Tensor(model, "input_a");
auto input_b = new Tensor(model, "input_b");
auto output = new Tensor(model, "result");
std::vector<float> data(100);
std::iota(data.begin(), data.end(), 0);
input_a->set_data(data);
input_b->set_data(data);
model.run({input_a, input_b}, output);
for (float f : output->get_data<float>()) {
std::cout << f << " ";
}
std::cout << std::endl;
}
Does anybody have any suggestions?

"Downloaded the tensorflow api files (copied them into the cppflow folder), "
Try downloading tensorflow_c_api into separate folder. No need to place inside cppflow directory.

Related

loading rosbag duration using cpp

I am interested to load contents of rosbag into databse using sqlite and c++.
while including rosbag/view.h and rosbag/bag.h header file in my cpp file in visual studio code I am facing error of no such file or directory
code: ref http://wiki.ros.org/rosbag/Cookbook#C.2B-.2B-
#include <ros/ros.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
int main(int argc, char **argv)
{
rosbag::Bag bag;
bag.open("input.bag", rosbag::bagmode::Read);
rosbag::View view(bag);
ros::Time bag_begin_time = view.getBeginTime();
ros::Time bag_end_time = view.getEndTime();
std::cout << "ROS bag time: " << (bag_end_time-
bag_begin_time).toSec() << "(s)" << std::endl;
bag.close();
return 0;
}
error:
main.cpp:2:10: fatal error: rosbag/bag.h: No such file or directory
2 | #include <rosbag/bag.h>
| ^~~~~~~~~~~~~~
Issue is resolved by including ros package, directories and libraries in the CmakeLists.txt and executing the code with cmake and make respectively now able to see the rosbag duration.
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(esw2 VERSION 0.0.1 LANGUAGES CXX)
find_package(rosbag REQUIRED)
add_executable(folder_name
file.cpp
)
target_include_directories(bag_reader
PUBLIC
include
${rosbag_INCLUDE_DIRS}
)
target_link_libraries(bag_reader
PRIVATE
${rosbag_LIBRARIES}
stdc++fs
)

Application using FFMPEG Library does not compile with CMAKE error avformat_alloc_context but I have imported the header files and libray

I compiled the FFMPEG source file myself and got the header and library files in an include and bin folder respectively, the target platform is Windows 10. I also setup my cmakelist.txt to find and include both the library and header files. The application finds the path or so it seems because during compilation I get a "LNK2019 error unresolved external symbol avformat_alloc_context referenced in function main". Below is an extract from my cmake list; I will like to note that I got the .lib and .dll versions of the library hence the approach below based on the book "professional cmake" and other stackflow examples.
ProjectDir/AudMan/cmakelist.txt
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};PATH-TO-INCLUDES;PATH-TO-LIBRARY)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)
add_library(ffmpegHeaders INTERFACE)
target_include_directories(ffmpegHeaders INTERFACE ${AVFORMAT_INCLUDE_DIR})
ProjectDir/cmakelist.txt
set(Rapid_Prefix PATH-TO-LIBRARY)
add_library(AVformat SHARED IMPORTED)
set_target_properties(AVformat PROPERTIES IMPORTED_LOCATION ${Rapid_Prefix}/avformat-59.dll IMPORTED_IMPLIB ${AVFORMAT_LIBRARY})
target_link_libraries(App_target PRIVATE AVformat)
A sample of the codes is this
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
int main()
{
AVFormatContext* format = avformat_alloc_context();
if (avformat_open_input(&format, R"(\test.m4a)", NULL, NULL) != 0) {
fprintf(stderr, "Could not open file '%s'\n", R"(\test.m4a)");
return -1;
}
if (avformat_find_stream_info(format, NULL) < 0) {
fprintf(stderr, "Could not retrieve stream info from file '%s'\n", R"(test.m4a)");
return -1;
}
return 0;
}
I have been at it for about five days and will appreciate any help I can get.

Unresolved External Symbol Error C++ While Adding New Library

I am trying to use Blaze C++ Library so I downloaded this library and successfully added to my project and used basic functionalities , but for extra functionalities I have to add BLAS and LAPACK library too. so i downloaded these packages .lib and .dll files. I did these:
1 - Project >> Linker >> General >> Additional Library Directories : I defined the path contains .dll files
2 - Project >> Linker >> Input >> Additional Dependencies : I defined the path contains .lib files
but when I try below code I receive some errors:
Code
#include <iostream>
#include <blaze/Math.h>
using namespace blaze;
using namespace std;
int main()
{
StaticMatrix<double,100,100> A;
for (size_t i = 0; i < 100; i++)
{
for (size_t j = 0; j < 100; j++)
{
A(i, j) = i + j;
}
}
blaze::DynamicMatrix<double, blaze::rowMajor> L, U, P;
lu(A, L, U, P);
}
Errors
1 - Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol dgetrf_ referenced in function "void __cdecl
blaze::getrf(int,int,double *,int,int *,int *)" (?getrf#blaze##YAXHHPEANHPEAH1#Z) MyProject
D:\C++\MyProject \MyProject \MyProject.obj 1
2 - Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals MyProject D:\C++\MyProject\x64\Debug\MyProject.exe 1
what should have I do ?

Error compiling a cpp file (ros)

I'm working on knowrob package and I already wrote my ontology(XML file) with Protege.
If I parse the owl.file and send some queries I have right answers.
Now my problem is to make a cpp to parse my xml file.
I already read something about json_prolog to send queries from my program to knowrob but is too muddler(http://www.knowrob.org/doc/interact_with_knowrob_via_ros).
I create my launch file and it works,later when i try to compile this cpp file:
#include <string>
#include <ros/ros.h>
#include <json_prolog/prolog.h>
using namespace std;
using namespace json_prolog;
int main(int argc, char *argv[])
{
ros::init(argc, argv, "test_json_prolog");
Prolog pl;
PrologQueryProxy bdgs = pl.query("member(A, [1, 2, 3, 4]), B = ['x', A], C = foo(bar, A, B)");
for(PrologQueryProxy::iterator it=bdgs.begin();
it != bdgs.end(); it++)
{
PrologBindings bdg = *it;
cout << "Found solution: " << (bool)(it == bdgs.end()) << endl;
cout << "A = "<< bdg["A"] << endl;
cout << "B = " << bdg["B"] << endl;
cout << "C = " << bdg["C"] << endl;
}
return 0;
}code here
I have the error:
/tmp/cccLQk3H.o:test_json_prolog.cpp:function main: error: undefined reference to 'ros::init(int&, char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
and other similar error about the undefined reference.
CMakelist :
cmake_minimum_required(VERSION 2.8.3)
project(json_prolog)
find_package(catkin REQUIRED rosjava_build_tools roscpp rospy json_prolog_msgs)
catkin_rosjava_setup(installApp publishMavenJavaPublicationToMavenRepository writeClasspath)
install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/knowrob/${PROJECT_NAME}/
DESTINATION ${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/knowrob/${PROJECT_NAME})
catkin_package(INCLUDE_DIRS include LIBRARIES json_prolog CATKIN_DEPENDS json_prolog_msgs )
# find SWI Prolog libraries
include(FindPkgConfig)
pkg_check_modules(SWIPL REQUIRED swipl)
include_directories(${SWIPL_INCLUDE_DIRS})
link_directories(${SWIPL_LIBRARY_DIRS})
# export Python libraries
catkin_python_setup()
# C++ client library
include_directories(include ${catkin_INCLUDE_DIRS})
find_package(PkgConfig)
pkg_check_modules(JSON_GLIB REQUIRED json-glib-1.0)
add_definitions(${JSON_GLIB_CFLAGS})
link_directories(${JSON_GLIB_LIBRARIY_DIRS})
How can I solve it?
You should start investigating with checking if your call to find_package() (you called find_package(), right?) was successful, so change the snippet you added in your question by adding a debug line,
message(STATUS ${catkin_LIBRARIES})
add_executable(test_json_prolog examples/test_json_prolog.cpp)
target_link_libraries(test_json_prolog json_prolog ${catkin_LIBRARIES})
add_dependencies(test_json_prolog ${catkin_EXPORTED_TARGETS})
Call to message should be printing the libraries you meant to link to.
Besides, see this page if you haven't already, http://wiki.ros.org/catkin/CMakeLists.txt. There they mention a custom macro that you MUST call, i.e. catkin_package(). Also the sections 6, 7, and 8 are all linked to your problem I guess.
You can try to compile it directly using g++ compiler.
Please check this answer:
Compile roscpp without ros (using g++)
There a source code is compiled without cmake or catkin_make

MSVS 2012 Express - Boost - Linker error LNK2019

I'm trying to build a project that's using some functionality of the file system part of the Boost library and I keep getting linker errors.
I followed the Boost documentation to build it and it built successfully and then moved all the lib files from the stage directory to C:/boost/lib and the hpp files to C:/boost/include. I'm using Microsoft Visual Studio 2012 Express Edition. I've made sure to add the files (libboost_filesystem-vc110-mt-1_54.lib and libboost_system-vc110-mt-1_54.lib) in the properties page to the files that need to be linked in (I also tried it with the #pragma's explicitly). I tried both the .lib files containing gd and the ones that dont (the debugging ones and the ones that aren't for debugging).
My question is, how do I fix this? Did I build the files wrong? Did I specify some sort of linker property wrong?
Here's the errors (I omitted some to keep it short, if needed I can add them all):
Error 1 error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat#system#boost##YAXXZ) C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
Error 2 error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat#system#boost##YAXXZ) C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
[...]
Error 5 error LNK2019: unresolved external symbol "public: class boost::filesystem::path __cdecl boost::filesystem::path::root_path(void)const " (?root_path#path#filesystem#boost##QEBA?AV123#XZ) referenced in function main C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
Error 6 error LNK2019: unresolved external symbol "public: class boost::filesystem::path __cdecl boost::filesystem::path::root_name(void)const " (?root_name#path#filesystem#boost##QEBA?AV123#XZ) referenced in function main C:\Visual Studio 2012 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj MMS_Prj_FindFile
[...]
Error 18 error LNK1120: 17 unresolved externals C:\Visual Studio 2012 Projects\MMS_Solution\x64\Debug\MMS_Prj_FindFile.exe MMS_Prj_FindFile
Here's the linker options (if others are needed I can add them):
Linker -> General
Enabled Incremental Linking = Yes (/INCREMENTAL)
Ignore Import LIbrary = No
Register Output = No
Per-user Redirection = No
Additional Library Directories = C:\openssl\lib;C:\boost\lib
Link Library Dependencies = Yes
Use Library Dependency Inputs = No
Prevent Dll Binding =
Linker -> Input
All of these are blank except for
Additional Dependencies = ssleay32.lib;libeay32.lib;Ws2_32.lib;libboost_system-vc110-mt-1_54.lib;libboost_filesystem-vc110-mt-1_54.lib;%(AdditionalDependencies)
Here's the code:
//Boost Includes
#include <boost/filesystem.hpp>
//Boost linking because visual studio won't link it (ugh)
#pragma comment (lib, "libboost_system-vc110-mt-gd-1_54.lib")
#pragma comment (lib, "libboost_filesystem-vc110-mt-gd-1_54.lib")
//Normal Includes
#include <iostream>
#include <string>
namespace bfs = boost::filesystem;
int main(int argc, char* argv[])
{
std::vector<std::string> foundPaths;
bfs::directory_iterator eit;
for(bfs::directory_iterator it("."); it != eit; it++)
{
if(!bfs::is_regular_file(it->status()))
continue;
bfs::path foundPath = it->path();
foundPaths.push_back("Root name: " + foundPath.root_name().string() + "\n" +
"Root dir : " + foundPath.root_directory().string() + "\n" +
"Root path: " + foundPath.root_path().string() + "\n" +
"Rel path: " + foundPath.relative_path().string() + "\n" +
"Prnt path: " + foundPath.parent_path().string() + "\n" +
"File name: " + foundPath.filename().string() + "\n" +
"Stem : " + foundPath.stem().string() + "\n" +
"Extension: " + foundPath.extension().string() + "\n");
}
for(std::vector<std::string>::iterator it = foundPaths.begin(); it != foundPaths.end(); ++it)
{
std::cout << *it << std::endl;
}
return 0;
}
When building Boost, make sure that you're using the parameter "address-model=64" if you're building for 64 bit. It says in the documentation that your compiler should choose the right one if it is configured correctly but apparently mine was not and was building 32 bit binaries when I wanted 64 bit binaries.