我在从静态库生成共享对象时遇到问题.虽然我知道还有其他选择,但我现在很困扰(而不是卡住)为什么这不起作用以及如何使其发挥作用.
下面是我正在使用的非常简单的源代码.
get_zero.c
#include "get_zero.h"
int
get_zero(void)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
get_zero.h
int get_zero(void);
Run Code Online (Sandbox Code Playgroud)
main.c中
#include <stdio.h>
#include <string.h>
#include "get_zero.h"
int
main(void)
{
return get_zero();
}
Run Code Online (Sandbox Code Playgroud)
目标是使用libget_zero_static和libget_zero_shared创建两个功能相同的应用程序.
这是我的编译/链接步骤:
gcc -c -fPIC get_zero.c
ar cr libget_zero_static.a get_zero.o
gcc -shared -o libget_zero_shared.so -L. -Wl,--whole-archive -lget_zero_static -Wl,-no--whole-archive
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.a(init-first.o): relocation R_X86_64_32 against `_dl_starting_up' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.a(init-first.o): could not read symbols: Bad value
collect2: ld returned 1 exit …Run Code Online (Sandbox Code Playgroud) 出于学习目的,我想编写一个Android应用程序,它将显示从0到Integer.MAX_VALUE的数字列表.我目前有一个应用程序将显示0到100之间的数字,这很简单,因为你可以创建一个数字数组,然后将其传递给适配器,目前使用ArrayAdapter.如果我尝试使用一个非常大的数组,程序在使用所有可用内存时会崩溃.
查看更高级的应用程序,我注意到人们使用数据库和CursorAdapter来处理大型数据集.如果这是正确的事情,我可以开始阅读.我想做什么(虽然随意告诉我这是错的)是种子我的ArrayAdapter有一个长度为100的数组,或者一些相对较小的长度.当用户向上或向下滚动时,我希望修改数组(或适配器)中的值,以便在用户向下滚动时增加,删除列表中的最小项并将更大的值附加到列表的末尾.如果用户向上滚动,我想从列表末尾删除项目并在开头添加新的较小值.
正如我在这个项目中所说,到目前为止我做得很少.
package example.VariableListView;
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class variablelistview extends ListActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
ArrayList<Integer> intItems = new ArrayList<Integer>();
for (int ii = 0; ii < 100; ii++) {
intItems.add(ii);
}
this.setListAdapter(new ArrayAdapter<Integer>(this,
android.R.layout.simple_list_item_1, intItems));
}
Run Code Online (Sandbox Code Playgroud)
}
提前感谢任何和所有的帮助.
我为Android 2.2构建了这个
这是我的代码.java是由eclipse生成的.xml我改变了.
package foo.bar.radiobuttontest;
import android.app.Activity;
import android.os.Bundle;
import foo.bar.radiobuttontest.R;
public class rbt extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup
android:id="@+id/orientation"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5px">
<RadioButton
android:id="@+id/horizontal"
android:background="#aa0000"
android:text="horizontal"
/>
<RadioButton
android:id="@+id/vertical"
android:text="vertical"
/>
</RadioGroup>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在尝试使用radiobuttons时,我开始制作一个非常简单的应用程序.它看起来像这样:
*水平垂直
无缘无故,我以为我会改变背景颜色.我开始改变RadioGroup元素的背景,一切都按预期工作.然后只是为了好玩我虽然我会改变组中只有一个单选按钮的背景.这可以在上面的main.xml中看到.在这之后,我注意到radiobutton的文本现在由radiobutton覆盖,页面现在看起来像:
*rizontal*垂直
除了你仍然可以从水平方向看到'ho',它们只是被radiobutton所覆盖
这是预期的行为吗?
我以为我开始掌握C++了......
然后我写了我认为我们非常简单的模板化函数,突然间它似乎再没有任何意义.编译器似乎甚至不喜欢我已定义模板化函数的事实,这看起来有点疯狂.它是单个编译单元,所以我不确定它会抱怨什么.
#include <vector>
#include <iostream>
typedef std::vector<int> int_vec_type;
template <typename Type>
bool print_vec(Type::const_iterator itr, const Type::const_iterator end)
{
for (; itr != end; ++itr) {
std::cout << *itr << std::endl;
}
return true;
}
int
main()
{
int_vec_type ivec;
ivec.push_back(0);
ivec.push_back(1);
ivec.push_back(2);
print_vec(ivec.begin(), ivec.end());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这些是编译错误:
tia.cc:7:22:错误:'bool print_vec'的模板声明
tia.cc:7:37:错误:预期')'在'itr'之前
tia.cc:7:42:错误:在'const'之前预期的primary-expression
tia.cc:在函数'int main()'中:
tia.cc:25:39:错误:'print_vec'未在此范围内声明
提前致谢.