I have a sample file like so, lets call it dnn_mmod_face_detection_ex.cpp
#include <iostream>
#include <dlib/dnn.h>
#include <dlib/data_io.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
using namespace std;
using namespace dlib;
// ----------------------------------------------------------------------------------------
template <long num_filters, typename SUBNET> using con5d = con<num_filters,5,5,2,2,SUBNET>;
template <long num_filters, typename SUBNET> using con5 = con<num_filters,5,5,1,1,SUBNET>;
template <typename SUBNET> using downsampler = relu<affine<con5d<32, relu<affine<con5d<32, relu<affine<con5d<16,SUBNET>>>>>>>>>;
template <typename SUBNET> using rcon5 = relu<affine<con5<45,SUBNET>>>;
using net_type = loss_mmod<con<1,9,9,1,1,rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>;
// ----------------------------------------------------------------------------------------
int main(int argc, char** argv) try
{
if (argc == 1)
{
cout << "Call this program like this:" << endl;
cout << "./dnn_mmod_face_detection_ex mmod_human_face_detector.dat faces/*.jpg" << endl;
cout << "\nYou can get the mmod_human_face_detector.dat file from:\n";
cout << "http://dlib.net/files/mmod_human_face_detector.dat.bz2" << endl;
return 0;
}
net_type net;
deserialize(argv[1]) >> net;
image_window win;
for (int i = 2; i < argc; ++i)
{
matrix<rgb_pixel> img;
load_image(img, argv[i]);
// Upsampling the image will allow us to detect smaller faces but will cause the
// program to use more RAM and run longer.
while(img.size() < 1800*1800)
pyramid_up(img);
// Note that you can process a bunch of images in a std::vector at once and it runs
// much faster, since this will form mini-batches of images and therefore get
// better parallelism out of your GPU hardware. However, all the images must be
// the same size. To avoid this requirement on images being the same size we
// process them individually in this example.
auto dets = net(img);
win.clear_overlay();
win.set_image(img);
for (auto&& d : dets)
win.add_overlay(d);
cout << "Hit enter to process the next image." << endl;
cin.get();
}
}
catch(std::exception& e)
{
cout << e.what() << endl;
}
I have a Makefile like so
CC=g++
CFLAGS=-c -Wall -std=c++11 -v
LDFLAGS=-L/usr/local/cuda/lib64 -ldlib -lcudnn -lpthread -ldl -lrt -lX11 -lcublas -lcudnn -lcurand -lcusolver -lstdc++ -lm -lgcc_s -lc -lxcb -lXau -lXdmcp
SOURCES=dnn_mmod_face_detection_ex.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=dnn_mmod_face_detection_ex
INCLUDE=
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDE) $< -o $#
But I get undefined references to almost every dlib library. ie
dnn_mmod_face_detection_ex.cpp:(.text+0x267): undefined reference to `dlib::image_window::image_window()'
dnn_mmod_face_detection_ex.cpp:(.text._ZNK4dlib8gpu_data4hostEv[_ZNK4dlib8gpu_data4hostEv]+0x14): undefined reference to `dlib::gpu_data::copy_to_host() const'
dnn_mmod_face_detection_ex.cpp:(.text._ZN4dlib16resizable_tensorC2Ev[_ZN4dlib16resizable_tensorC5Ev]+0x31): undefined reference to `dlib::cuda::tensor_descriptor::tensor_descriptor()'
I know the following
This same example is compiled and is runs inside the /dlib/build/test... directory (dlib-19.9)
Those LDFLAGS I obtained by issuing the command ldd /dlib/build/test.../dnn_mmod_face_detection_ex
What is the right way to figure out what libraries are missing? I tried tracing the Cmake file(s) that dlib provided but it is more complicated than a particle accelerator.
It was a simple mistake of misplacing the LDFLAGS. It works when placed at the end like so
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o $# $(LDFLAGS)
Related
I have a project with the following structure:
Item.cpp
Item.h
main.cpp
Makefile
The following source code is in the Item.h file:
class Item {
public:
Item();
~Item();
};
The following source code is in the Item.cpp file:
#include <iostream>
#include "Item.h"
Item::Item() {
std::cout << "Item created..." << std::endl;
}
Item::~Item() {
std::cout << "Item destroyed..." << std::endl;
}
The following source code is the content of the main.cpp file:
#include "Item.h"
#include <iostream>
int main() {
std::cout << "Initialize program..." << std::endl;
Item item_1();
std::cout << "Hello world!" << std::endl;
return 0;
}
And finally, the following source code is the Makefile file:
CXX = g++
all: main item
$(CXX) -o sales.o main.o Item.o
main:
$(CXX) -c main.cpp
item:
$(CXX) -c Item.cpp
clean:
rm -rf *.o
When I run the make command and then I run the compiled code with the command ./sales.o, I get the following output:
Initialize program...
Hello world!
Why is the output of the constructor method of the class Item not printed in the console? I found in some web pages that you can compile the source codes in steps and then you can link it with the -o option when using g++ but it does not work in this case. How can I compile this source codes step by step and then link it in the Makefile?
I'm surely you ignored this warning :
warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
#include "Item.h"
#include <iostream>
int main() {
std::cout << "Initialize program..." << std::endl;
Item item_1;
std::cout << "Hello world!" << std::endl;
return 0;
}
just remove parentheses it will be work
test : https://godbolt.org/z/KrdrhvsrW
I need to use cygwin compiled dll from visual studio C++ or Code:blocks MinGW.
I tried use this simple example
#include <stdio.h>
int MyFunc()
{
printf("Printed from cygwin dll");
return 0;
}
And this makefile
obj = mydll.o
ALLLIBS = \
mydll.a \
mydll.dll
all: $(ALLLIBS)
mydll.a: $(obj)
$(LINK.a)
mydll.dll: $(obj)
$(cygTest.dll)
cygTest.dll = gcc -shared -o cygTest.dll \
-Wl,--out-implib \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--whole-archive $(obj) \
-Wl,--no-whole-archive
mydll.a = ar $(ARFLAGS) $# $%
I am trying to call the final dll here.
#include <windows.h>
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
typedef int(*FnP_MyFunc)();
typedef void(*FnP_CYGWIN_DLL_INIT)();
int main()
{
FnP_MyFunc fnMyFunc;
HMODULE hLib, hGetCygwinIDDLL = LoadLibrary(TEXT("C:\\cygwin64\\bin\\cygwin1.dll"));
if (hGetCygwinIDDLL)
{
FnP_CYGWIN_DLL_INIT init = (FnP_CYGWIN_DLL_INIT)GetProcAddress(hGetCygwinIDDLL, "cygwin_dll_init");
init();
std::cout << "init complete " << endl;
}
int a;
hLib = LoadLibrary(TEXT("C:\\cygwin64\\home\\azatyan\\TestDynamicLink\\cygTest.dll"));
if (hLib)
{
std::cout << "From wrapper dll " << std::endl;
fnMyFunc = (FnP_MyFunc)GetProcAddress(hLib, "MyFunc");
a = fnMyFunc();
cout << a;
}
FreeLibrary(hGetCygwinIDDLL);
FreeLibrary(hLib);
return 0;
}
And it just hangs when it reaches to my MyFunc function. Or exits with code 1536..
Can anybody help me, what am I doing wrong?
UPDATE: I have tried the same without printf() function, worked ok, returned expected value, this means that the problem is in dependency libraries, but still I don't know haw I can add all dependency libraries..
I get the error "No such file or directory" when I run this at the top of my main:
Edit- This is my complete .cpp file:
#include <iostream>
#include <fstream>
#include <sstream>
#include "CommunicationNetwork.h"
using namespace std;
int DisplayMenu();
int main(int argc, char* argv[])
{
ifstream file;
string data;
file.open("message.txt");
if(file.is_open()){
cout << "WORKS" << endl;
}else {
cerr << "Error: " << strerror(errno) << endl;
}
CommunicationNetwork network;
bool gbye = false;
while(gbye == false){
int use = DisplayMenu();
switch(use) {
case 1:
network.buildNetwork();
break;
case 2:
network.printNetwork();
break;
case 3:
network.transmitMsg("message.txt");
break;
case 4: cout << "Add" << endl;
break;
case 5:
cout << "Goodbye!" << endl;
gbye = true;
}
}
return 0;
}
I have used this method countless times to open txt files but this is the first time I am using a makefile with my program which I'm guessing is the cause of the problem.
Does "message.txt" need to appear in my makefile somewhere? Is so where? What if I want to pass the filename as a command line argument?
My makefile looks like:
PROG = com
CC = g++
OBJS = CommunicationNetwork.o Assignment.o
CPPFLAGS = -Wall -std=c++11
$(PROG) : $(OBJS)
$(CC) -o $(PROG) $(OBJS)
CommunicationNetwork.o : CommunicationNetwork.h
$(CC) $(CPPFLAGS) -c CommunicationNetwork.cpp
Assignment.o :
$(CC) $(CPPFLAGS) -c Assignment.cpp
clean:
$(RM) $(PROG) $(OBJS)
The .txt file is saved in the same folder as my other files. I will get the error regardless of what .txt file I try. Let me know if more information is needed. Thanks!
Edit:
Both the .cpp and the .txt file are in the folder Assignment
for message.txt: /Users/tannerquigley/Library/Mobile Documents/com~apple~CloudDocs/School/CSCI 2270/Assignment
for Assignment.cpp: /Users/tannerquigley/Library/Mobile Documents/com~apple~CloudDocs/School/CSCI 2270/Assignment
in Terminal: res1-131-132-dhcp:Assignment tannerquigley$ make after I run a make clean
And then I open the "com" executable file that appears in the Assignment folder
Do not run the Unix Executable File that appears in the Folder. Run the program from the same terminal window using the command ./com or whatever you (I) named the program in the Makefile.
So i'm just trying to compile this sample mysql C++ program. It will compile and run just fine if i put g++ -Wall -I/usr/include/cppconn -o mysql_test mysql_test.cpp -L/usr/lib -lmysqlcppconn on the command line. If i try to use make, it fails due to a undefined function call. What is wrong with the make script?
g++ -o prog mysql_test.o
mysql_test.o: In function main':
mysql_test.cpp:(.text+0x3a): undefined reference toget_driver_instance'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
Here is the make file:
CXX=g++
#CXXFLAGS=-g -std=c++0x -Wall -pedantic -lmysqlcppconn -lmysqlcppconn-static
CXXFLAGS=-g -std=c++0x -Wall -I/usr/include/cppconn -L/usr/lib -lmysqlcppconn
BIN=prog
SRC=$(wildcard *.cpp)
OBJ=$(SRC:%.cpp=%.o)
all: $(OBJ)
$(CXX) -o $(BIN) $^
%.o: %.c
$(CXX) $# -c $<
clean:
rm -f *.o
rm $(BIN)
Here is the cpp source:
#include <stdlib.h>
#include <iostream>
/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "password");
/* Connect to the MySQL test database */
con->setSchema("mysql");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column fata by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
Thanks for any help with this.
Here is the working make:
CXX=g++
#CXXFLAGS=-g -std=c++0x -Wall -pedantic -lmysqlcppconn -lmysqlcppconn-static
CXXFLAGS=-g -std=c++0x -Wall -I/usr/include/cppconn
LDFLAGS=-L/usr/lib -lmysqlcppconn
BIN=prog
SRC=$(wildcard *.cpp)
OBJ=$(SRC:%.cpp=%.o)
all: $(OBJ)
$(CXX) -o $(BIN) $(LDFLAGS) $^
%.o: %.c
$(CXX) $# -c $<
clean:
rm -f *.o
rm $(BIN)
-L/usr/lib -lmysqlcppconn needs to be in LD_FLAGS.
I have the following defined in the header file:
some function ...
if (table2[i] != ""){
new_table2[hash2(table2[i])] = table2[i];
table2[i] = "";
}
// std::cout << " first i : " << i << "\n";
}
for (int i=0; i < 150; ++i){
if (new_table1[i] != "" && !try_insert(new_table1[i])){
std::cout << " bad rehash : " << i << " " << new_table1[i] << "\n";
rehash();
}
}
Makefile looks like this:
CC=g++
CFLAGS=-Wall -Wextra -O3.
DEPS = somehash.h hashfunctions.h
OBJ = main.o
%.o: %.c $(DEPS)
$(CC) -c -o $# $< $(CFLAGS)
main: $(OBJ)
g++ -o $# $^ $(CFLAGS)
.PHONY: clean
clean:
rm -f *.o main
After I do make clean, make, and ./main, "first i" is still printed even though it is commented out. When I comment out " bad rehash ", then both of them are not printed. It seems the compiler did some auto optimization that causes this to be cached? How can I fix it?
Edit: I opened the file in another editor (was using Sublime), and the problem went away. It seem the problem is sublime.