In my ubuntu 14.xx, I try to compile lsnes emulator to use the mario-ai script from aleju/mario-ai, and I've tried to google many solutions to solve the problem below:
Here is the output from the console:
make[3]: __all__.files' is up to date.
make[3]: Leaving directory/home/pengsuyu/software/lsnes/sourcecode/src/platform/macosx'
make[2]: Leaving directory /home/pengsuyu/software/lsnes/sourcecode/src/platform'
g++ -o lsnescat all_common.files all_platform.files-pthread -lboost_iostreams -lboost_filesystem -lboost_system -lz -lgcrypt -lgpg-error -L/usr/lib/x86_64-linux-gnu -lcurl -rdynamic -ldlcat core/all.ldflags lua/all.ldflags fonts/all.ldflags library/all.ldflags interface/all.ldflags video/all.ldflags emulation/all.ldflags cmdhelp/all.ldflags platform/all.ldflags
core/multitrack.o: In functionlua::state::get_string(int, std::string const&)':
/home/pengsuyu/software/lsnes/sourcecode/src/core/../../include/library/lua-base.hpp:317: undefined reference to lua_tolstring'
core/multitrack.o: In functionlua::state::get_bool(int, std::string const&)':
/home/pengsuyu/software/lsnes/sourcecode/src/core/../../include/library/lua-base.hpp:334: undefined reference to lua_toboolean'
core/multitrack.o: In functionlua::state::type(int)':
.
.
/home/pengsuyu/software/lsnes/sourcecode/src/library/lua.cpp:536: undefined reference to lua_close'
library/lua.o: In functionlua::state::pushcfunction(int ()(lua_State))':
/home/pengsuyu/software/lsnes/sourcecode/src/library/../../include/library/lua-base.hpp:504: undefined reference to lua_pushcclosure'
library/lua.o: In functionlua::state::getfield(int, char const*)':
/home/pengsuyu/software/lsnes/sourcecode/src/library/../../include/library/lua-base.hpp:506: undefined reference to lua_getfield'
library/lua.o: In functionlua::state::insert(int)':
/home/pengsuyu/software/lsnes/sourcecode/src/library/../../include/library/lua-base.hpp:509: undefined reference to lua_insert'
collect2: error: ld returned 1 exit status
make[1]: *** [lsnes] Error 1
make[1]: Leaving directory/home/pengsuyu/software/lsnes/sourcecode/src'
make: *** [src/all_files] Error 2
==================================
At the beginning, I think, the linker cannot find my lua library. So I tried to compile my main.cpp with test.lua.
main.cpp:
#include <stdio.h>
#include <iostream>
//extern "C"
//{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
//} // liblua5.1-c++.a
lua_State * L;
int main ()
{
L = lua_open();
luaL_openlibs(L);
luaL_dofile(L, "d:\\test.lua");
return 0;
}
test.lua:
print("Hello World");
I write a MakeFile to generate the executable file "main":
main:main.o
gcc -o $# $< -llua5.1 -lstdc++
main.o:
gcc -c main.cpp
clean:
-rm *.o
It works when I add the compile option "-llua5.1" and "-lstdc++" otherwise it throws the same error as I compiled lsnes
I am not familiar with gcc and Makefile. Please help me to solve this problem.
I've solved my question
The way to solve this problem is just to change one line in the file named "options.build".
1. find the line "LUA=lua" in options.build
2. change this line to "LUA=lua5.1"
because the needed library is 5.1, so if you want to build it successfully, you must use the "lua5.1" library however the default configuration is "lua" not "lua5.1"
Related
Hopefully someone can help with this.
After rebuilding OpenCV 2.4.6 with Cuda Toolkit 5.5 on linux, an attempt was made to build a single c++ file that references OpenCV and CUDA using via make and a CLI g++ command. The input and output from each approach are shown below.
The Makefile attempts to reference the *.a files from OpenCV, but is not successful. The CLI g++ command attempts to reference *.so files, which it seems to do, however, some methods appear to be undefined.
Is it necessary for the Makefile to access only the OpenCV *.a files?
Makefile:
CFLAGS = -g Wall
LIBPATH = /data/content/cuda/opencv-2.4.6/lib
LIBS = -lopencv_calib3d_pch_dephelp -lopencv_contrib_pch_dephelp -lopencv_core_pch_dephelp -lopencv_features2d_pch_dephelp -lopencv_flann_pch_dephelp -lopencv_gpu_pch_dephelp -lopencv_haartraining_engine -lopencv_highgui_pch_dephelp -lopencv_imgproc_pch_dephelp -lopencv_legacy_pch_dephelp -lopencv_ml_pch_dephelp -lopencv_nonfree_pch_dephelp -lopencv_objdetect_pch_dephelp -lopencv_perf_calib3d_pch_dephelp -lopencv_perf_core_pch_dephelp -lopencv_perf_features2d_pch_dephelp -lopencv_perf_gpu_pch_dephelp -lopencv_perf_highgui_pch_dephelp -lopencv_perf_imgproc_pch_dephelp -lopencv_perf_nonfree_pch_dephelp -lopencv_perf_objdetect_pch_dephelp -lopencv_perf_photo_pch_dephelp -lopencv_perf_stitching_pch_dephelp -lopencv_perf_superres_pch_dephelp -lopencv_perf_video_pch_dephelp -lopencv_photo_pch_dephelp -lopencv_stitching_pch_dephelp -lopencv_superres_pch_dephelp -lopencv_test_calib3d_pch_dephelp -lopencv_test_contrib_pch_dephelp -lopencv_test_core_pch_dephelp -lopencv_test_features2d_pch_dephelp -lopencv_test_flann_pch_dephelp -lopencv_test_gpu_pch_dephelp -lopencv_test_highgui_pch_dephelp -lopencv_test_imgproc_pch_dephelp -lopencv_test_legacy_pch_dephelp -lopencv_test_ml_pch_dephelp -lopencv_test_nonfree_pch_dephelp -lopencv_test_objdetect_pch_dephelp -lopencv_test_photo_pch_dephelp -lopencv_test_stitching_pch_dephelp -lopencv_test_superres_pch_dephelp -lopencv_test_video_pch_dephelp -lopencv_ts_pch_dephelp -lopencv_video_pch_dephelp -lopencv_videostab_pch_dephelp -lopencv_gpu -lopencv_highgui
INCLUDEPATH1 = /usr/include/opencv2/core
INCLUDEPATH2 = /usr/include/opencv2/highgui
INCLUDEPATH3 = /usr/include/opencv2/gpu
all: tiff2png1.so
tiff2png1.so: main.o
g++ -o tiff2png1.so main.o **-L $(LIBPATH) $(LIB)**
main.o: main.cpp
g++ -c main.cpp -g -Wall -I $(INCLUDEPATH1) -I $(INCLUDEPATH2) -I $(INCLUDEPATH3) $(LIBPATH)
.PHONY: clean
clean:
rm -vf tiff2png1.so *.o
Makefile Output:
g++ -o tiff2png1.so main.o -L /data/content/cuda/opencv-2.4.6/lib
main.o: In function main':
/home/.../main.cpp:13: undefined reference tocv::gpu::getCudaEnabledDeviceCount()'
/home/.../main.cpp:15: undefined reference to cv::gpu::getDevice()'
/home/.../main.cpp:21: undefined reference tocv::imread(std::basic_string, std::allocator > const&, int)'
/home/.../main.cpp:27: undefined reference to cv::gpu::GpuMat::GpuMat(cv::Mat const&)'
/home/.../main.cpp:29: undefined reference tocv::gpu::Stream::Null()'
/home/.../main.cpp:29: undefined reference to cv::gpu::resize(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, cv::Size_<int>, double, double, int, cv::gpu::Stream&)'
/home/.../main.cpp:42: undefined reference tocv::Mat::Mat(cv::gpu::GpuMat const&)'
/home/.../main.cpp:49: undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)'
...
main.o: In function~GpuMat': /usr/include/opencv2/core/gpumat.hpp:374: undefined reference to `cv::gpu::GpuMat::release()'
collect2: ld returned 1 exit status
make: * [tiff2png1.so] Error 1
Command Line Build
$ g++ -o tx.exe main.o -L/data/content/cuda/opencv-2.4.6/lib -lopencv_gpu
Command Line Build Output
/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::convertTo(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, CUstream_st*)'
/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&, cv::Scalar_, cv::gpu::GpuMat const&, CUstream_st*)'
/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&, cv::Scalar_, CUstream_st*)'
collect2: ld returned 1 exit status
It looks like you may have omitted an 'S' at the end of your variable in the linker target
**LIBS** = -lopencv_calib3d_pch_dephelp ...
tiff2png1.so: main.o
g++ -o tiff2png1.so main.o -L $(LIBPATH) $(**LIB**)
and so the -l options aren't being passed to the linker
g++ -o tiff2png1.so main.o -L /data/content/cuda/opencv-2.4.6/lib **should be here** main.o
I tried a sample opencv program to run on cuda. I have doownloaded opencv and compiled it and as last step run make install and it went successfull.
I tried the following program
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
int main (int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE);
cv::gpu::GpuMat dst, src;
src.upload(src_host);
cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);
cv::Mat result_host = dst;
cv::imshow("Result", result_host);
cv::waitKey();
}
catch(const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}
Saved this as test.cu and compiled. The output is
# nvcc test.cu
/tmp/tmpxft_000018a4_00000000-13_test.o: In function `main':
tmpxft_000018a4_00000000-1_test.cudafe1.cpp:(.text+0x53): undefined reference to `cv::imread(std::string const&, int)'
tmpxft_000018a4_00000000-1_test.cudafe1.cpp:(.text+0xf7): undefined reference to `cv::gpu::GpuMat::upload(cv::Mat const&)'
tmpxft_000018a4_00000000-1_test.cudafe1.cpp:(.text+0xfc): undefined reference to `cv::gpu::Stream::Null()'
tmpxft_000018a4_00000000-1_test.cudafe1.cpp:(.text+0x130): undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)'
....................
.....................
.......................
Then I run
# nvcc test.cu -lopencv_gpu
/usr/bin/ld: /tmp/tmpxft_000018df_00000000-13_test.o: undefined reference to symbol '_ZTIN2cv9ExceptionE'
/usr/bin/ld: note: '_ZTIN2cv9ExceptionE' is defined in DSO /usr/local/lib/libopencv_core.so.2.4 so try adding it to the linker command line
/usr/local/lib/libopencv_core.so.2.4: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
and
# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2012 NVIDIA Corporation
Built on Thu_Apr__5_00:24:31_PDT_2012
Cuda compilation tools, release 4.2, V0.2.1221
UPDATE
# nvcc test.cu -lm -lopencv_core -lopencv_highgui
/tmp/tmpxft_00001c51_00000000-13_test.o: In function `main':
tmpxft_00001c51_00000000-1_test.cudafe1.cpp:(.text+0xfc): undefined reference to `cv::gpu::Stream::Null()'
tmpxft_00001c51_00000000-1_test.cudafe1.cpp:(.text+0x130): undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)'
collect2: error: ld returned 1 exit status
I gave
# nvcc test.cu -lm -lopencv_core -lopencv_highgui -lopencv_gpu
and its working fine.
Now I m getting following error when running
# ./a.out
OpenCV Error: Gpu API call (invalid configuration argument) in call, file /home/cuda/helloworld/Downloads/OpenCV/opencv-2.4.5/modules/gpu/include/opencv2/gpu/device/detail/transform_detail.hpp, line 361
Error: /home/cuda/helloworld/Downloads/OpenCV/opencv-2.4.5/modules/gpu/include/opencv2/gpu/device/detail/transform_detail.hpp:361: error: (-217) invalid configuration argument in function call
Add " -lm -lopencv_core -lopencv_highgui " options to your comile code
I think you got error because of library linking error.So try
As
nvcc test.cu `pkg-config --cflags --libs opencv` -lopencv_gpu
Or
nvcc test.cu -lm -lopencv_core -lopencv_highgui -lopencv_gpu.
I am building Nachos source on Ubuntu 12.04
If we believe "lscpu" output, machine arch is x86. I am getting the following error at the last step of make:
$ make
g++ -m32 -P -I../network -I../filesys -I../userprog -I../threads -I../machine -I../lib -iquote -Dx86 -DLINUX -c ../threads/switch.S
g++ bitmap.o debug.o libtest.o sysdep.o interrupt.o stats.o timer.o console.o machine.o mipssim.o translate.o network.o disk.o alarm.o kernel.o main.o scheduler.o synch.o thread.o addrspace.o exception.o synchconsole.o directory.o filehdr.o filesys.o pbitmap.o openfile.o synchdisk.o post.o switch.o -m32 -o nachos
scheduler.o: In function `Scheduler::Run(Thread*, bool)':
/home/userx/nachos/NachOS-4.0/code/build.linux/../threads/scheduler.cc:133: undefined reference to `SWITCH'
thread.o: In function `Thread::StackAllocate(void ()(void), void*)':
/home/userx/nachos/NachOS-4.0/code/build.linux/../threads/thread.cc:345: undefined reference to `ThreadRoot'
/home/userx/nachos/NachOS-4.0/code/build.linux/../threads/thread.cc:356: undefined reference to `ThreadRoot'
collect2: ld returned 1 exit status
make: * [nachos] Error 1
$
Here is the switch.S that has the symbol defs --
/* We define two routines for each architecture:
*
* ThreadRoot(InitialPC, InitialArg, WhenDonePC, StartupPC)
<...>
#ifdef SOLARIS
.globl ThreadRoot
ThreadRoot:
#else
.globl _ThreadRoot
_ThreadRoot:
#endif
#ifdef x86
.text
.align 2
.globl ThreadRoot
.globl _ThreadRoot
_ThreadRoot:
ThreadRoot:
<...>
.globl SWITCH
.globl _SWITCH
_SWITCH:
SWITCH:
<...>
#endif
I have skipped the #ifdefs for more arch like DECMIPS, POWERPC, APPLEPOWERPC etc.
Yes, my env $PATH includes dir where switch.s resides :/home/userx/nachos/NachOS-4.0/code/threads/
Please let me know if any more info is needed to debug. Thanks a lot.
Try adding underscore in the C header file that have extern "C" SWITCH and ThreadRoot, and change too the .c file in where the error is. I mean use _SWITCH instead SWITCH and the same for ThreadRoot.
I have one .cu file that contains my cuda kernel, and a wrapper function that calls the kernel. I have a bunch of .c files as well, one of which contains the main function. One of these .c files calls the wrapper function from the .cu to invoke the kernel.
I compile these files as follows:
LIBS=-lcuda -lcudart
LIBDIR=-L/usr/local/cuda/lib64
CFLAGS = -g -c -Wall -Iinclude -Ioflib
NVCCFLAGS =-g -c -Iinclude -Ioflib
CFLAGSEXE =-g -O2 -Wall -Iinclude -Ioflib
CC=gcc
NVCC=nvcc
objects := $(patsubst oflib/%.c,oflib/%.o,$(wildcard oflib/*.c))
table-hash-gpu.o: table-hash.cu table-hash.h
$(NVCC) $(NVCCFLAGS) table-hash.cu -o table-hash-gpu.o
main: main.c $(objects) table-hash-gpu.o
$(CC) $(CFLAGSEXE) $(objects) table-hash-gpu.o -o udatapath udatapath.c $(LIBS) $(LIBDIR)
So far everything is fine. table-hash-gpu.cu calls a function from one of the .c files. When linking for main, I get the error that the function is not present. Can someone please tell me what is going on?
nvcc compiles both device and host code using the host C++ compiler, which implies name mangling. If you need to call a function compiled with a C compiler in C++, you must tell the C++ compiler that it uses C calling conventions. I presume that the errors you are seeing are analogous to this:
$ cat cfunc.c
float adder(float a, float b, float c)
{
return a + 2.f*b + 3.f*c;
}
$ cat cumain.cu
#include <cstdio>
float adder(float, float, float);
int main(void)
{
float result = adder(1.f, 2.f, 3.f);
printf("%f\n", result);
return 0;
}
$ gcc -m32 -c cfunc.c
$ nvcc -o app cumain.cu cfunc.o
Undefined symbols:
"adder(float, float, float)", referenced from:
_main in tmpxft_0000b928_00000000-13_cumain.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Here we have code compiled with nvcc (so the host C++ compiler) trying to call a C function and getting a link error, because the C++ code expects a mangled name for adder in the supplied object file. If the main is changed like this:
$ cat cumain.cu
#include <cstdio>
extern "C" float adder(float, float, float);
int main(void)
{
float result = adder(1.f, 2.f, 3.f);
printf("%f\n", result);
return 0;
}
$ nvcc -o app cumain.cu cfunc.o
$ ./app
14.000000
It works. Using extern "C" to qualify the declaration of the function to the C++ compiler, it will not use C++ mangling and linkage rules when referencing adder and the resulting code links correctly.
I tried to link my executable program with 2 static libraries using g++. The 2 static libraries have the same function name. I'm expecting a "multiple definition" linking error from the linker, but I did not received. Can anyone help to explain why is this so?
staticLibA.h
#ifndef _STATIC_LIBA_HEADER
#define _STATIC_LIBA_HEADER
int hello(void);
#endif
staticLibA.cpp
#include "staticLibA.h"
int hello(void)
{
printf("\nI'm in staticLibA\n");
return 0;
}
output:
g++ -c -Wall -fPIC -m32 -o staticLibA.o staticLibA.cpp
ar -cvq ../libstaticLibA.a staticLibA.o
a - staticLibA.o
staticLibB.h
#ifndef _STATIC_LIBB_HEADER
#define _STATIC_LIBB_HEADER
int hello(void);
#endif
staticLibB.cpp
#include "staticLibB.h"
int hello(void)
{
printf("\nI'm in staticLibB\n");
return 0;
}
output:
g++ -c -Wall -fPIC -m32 -o staticLibB.o staticLibB.cpp
ar -cvq ../libstaticLibB.a staticLibB.o
a - staticLibB.o
main.cpp
extern int hello(void);
int main(void)
{
hello();
return 0;
}
output:
g++ -c -o main.o main.cpp
g++ -o multipleLibsTest main.o -L. -lstaticLibA -lstaticLibB -lstaticLibC -ldl -lpthread -lrt
The linker does not look at staticLibB, because by the time staticLibA is linked, there are no unfulfilled dependencies.
That's an easy one. An object is only pulled out of a library if the symbol referenced hasn't already been defined. Only one of the hellos are pulled (from A). You'd get errors if you linked with the .o files.
When the linker tries to link main.o into multipleLibsTest and sees that hello() is unresolved, it starts searching the libraries in the order given on the command line. It will find the definition of hello() in staticLibA and will terminate the search.
It will not look in staticLibB or staticLibC at all.
If staticLibB.o contained another symbol not in staticLibA and that was pulled into the final executable, you then get a multiple definition of hello error, as individual .o files are pulled out of the library and two of them would have hello(). Reversing the order of staticLibA and staticLibB on the link command line would then make that error go away.