我正在尝试创建一个指定了-fPIC
的静态库。
add_library(cpp-netlib_pic
STATIC
${SRCS})
set_property(TARGET cpp-netlib_pic PROPERTY POSITION_INDEPENDENT_CODE)
这不起作用。
库(cpp-netlib_pic
)的构建没有-fPIC
标志。
与cpp-netlib_pic
相关联的其他目标
执行但是,-fPIC
已添加到其编译器标志中,但链接失败,因为cpp-netlib_pic
没有。
此处foo
将添加-fPIC
:
add_library(foo
SHARED
${SRCS})
target_link_libraries(foo cpp-netlib_pic)
我用make VERBOSE = 1
证明了这一点[ 87%] Building CXX object third_party/cpp-netlib/CMakeFiles/cpp-netlib_pic.dir/src/server_request_parsers_impl.cpp.o
/usr/bin/c++ ... -std=c++14 -Werror -Wall -Wextra ... \
-o CMakeFiles/cpp-netlib_pic.dir/src/server_request_parsers_impl.cpp.o \
-c .../third_party/cpp-netlib/src/server_request_parsers_impl.cpp
请注意此处没有-fPIC
。
在构建使用foo
的目标cpp-netlib_pic
时,会出现-fPIC
:
[ 93%] Building CXX object foo.cc.o
/usr/bin/c++ ... -std=c++14 -Werror -Wall -Wextra ... -fPIC ... \
-o CMakeFiles/foo_shared_lib.dir/foo.cc.o \
-c .../foo/foo.cc
如何配置CMake以使用cpp-netlib_pic
构建第一个库(-fPIC
)?
答案 0 :(得分:8)
您似乎忘记了 private Adapter adapter;
private ListView listView;
private DatabaseReference reference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
listView = (ListView) findViewById(R.id.list);
adapter = new Adapter(this, R.id.list);
listView.setAdapter(adapter);
FirebaseDatabase database = FirebaseDatabase.getInstance();
reference = database.getReference("database");
reference.addChildEventListener(new com.google.firebase.database.ChildEventListener() {
@Override
public void onChildAdded(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
Project msg = dataSnapshot.getValue(Project.class);
adapter.add(msg);
adapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(com.google.firebase.database.DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Project selectedList = adapter.getItem(position);
if (selectedList != null) {
Intent intent = new Intent(Activity.this, Details_Project_Activity.class);
intent.putExtra(Constants.KEY_LIST_TITLE, selectedList.getTitle());
intent.putExtra(Constants.KEY_LIST_PLACE, selectedList.getPlace());
intent.putExtra(Constants.KEY_LIST_DATE, selectedList.getDate());
startActivity(intent);
}
}
});
}
:
ON