我需要帮助,我一直在同一台计算机上执行此操作,这意味着我已经安装了boost库,并且基于之前的代码,但这次它给了我错误: /tmp/ccpAYzPw.o:在函数`main':
import android.os.Environment;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;
public class SongsManager {
final String MEDIA_PATH = Environment.getExternalStorageDirectory().getPath() + "/";
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
private String mp3Pattern = ".mp3";
// Constructor
public SongsManager(){
}
/**
* Function to read all mp3 files from sdcard
* and store the details in ArrayList
* */
public ArrayList<HashMap<String, String>> getPlayList(){
System.out.println(MEDIA_PATH);
if (MEDIA_PATH != null) {
File home = new File(MEDIA_PATH);
File[] listFiles = home.listFiles();
if (listFiles != null && listFiles.length > 0) {
for (File file : listFiles) {
System.out.println(file.getAbsolutePath());
if (file.isDirectory()) {
scanDirectory(file);
} else {
addSongToList(file);
}
}
}
}
// return songs list array
return songsList;
}
private void scanDirectory(File directory) {
if (directory != null) {
File[] listFiles = directory.listFiles();
if (listFiles != null && listFiles.length > 0) {
for (File file : listFiles) {
if (file.isDirectory()) {
scanDirectory(file);
} else {
addSongToList(file);
}
}
}
}
}
private void addSongToList(File song) {
if (song.getName().endsWith(mp3Pattern)) {
HashMap<String, String> songMap = new HashMap<String, String>();
songMap.put("songTitle",
song.getName().substring(0, (song.getName().length() - 4)));
songMap.put("songPath", song.getPath());
// Adding each song to SongList
songsList.add(songMap);
}
}
/**
* Class to filter files which are having .mp3 extension
* */
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".mp3") || name.endsWith(".MP3"));
}
}
}
我花了将近2个小时才知道发生了什么事?但我无法理解为什么,所以我需要你的帮助。
这是我的代码,非常感谢你。
reading_data.cpp:(.text+0x356): undefined reference to `boost::program_options::options_description::m_default_line_length'
reading_data.cpp:(.text+0x361): undefined reference to `boost::program_options::options_description::m_default_line_length'
reading_data.cpp:(.text+0x3a6): undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
reading_data.cpp:(.text+0x3d3): undefined reference to `boost::program_options::options_description::add_options()'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'reading_data' failed
答案 0 :(得分:7)
您似乎没有链接库。 boost::program_options
不是标题,因此您必须明确链接它:
-lboost_program_options
答案 1 :(得分:1)
您意外地在以下行的末尾添加了一个多余的分号:
desc.add_options(); //是原帖中的拼写错误
您还需要声明用于存储输入选项的变量。
std::string sign;
double week, day, hour, minute, second;
desc.add_options()
("sign" , program_options::value<std::string>(&sign) -> default_value("gbm") ,"name of the input")
("week" , program_options::value<double>(&week) -> default_value(1930) ,"number of the week")
("day" , program_options::value<double>(&day) -> default_value(0) ,"number of the day in within the week")
("hour" , program_options::value<double>(&hour) -> default_value(0) ,"time in hour")
("minute", program_options::value<double>(&minute) -> default_value(0) ,"time in minute")
("second", program_options::value<double>(&second) -> default_value(0) ,"time in second")
;
答案 2 :(得分:0)
Boost program_options是一个已编译的库,而不是像许多其他boost库一样的头文件 因此,您需要在构建时将库链接到您的程序。
如何做到这一点在很大程度上取决于您使用的编译器和平台。
如果你不知道链接是什么,你可以在这里阅读: How does the compilation/linking process work?