Open lewisxy opened 6 years ago
You'll need to link both the .a
and .res
files in.
You'll need to use these link options:
-luser32 -lkernel32 -lusp10 -lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc
(At present, the order is important. If I find I don't need usp10
in the future, then this will stop being true.) You may also need to link with g++
instead of gcc
, but I'm not quite sure how this works.
For package ui, I also use -static -static-libgcc -static-libstdc++
. I do not know what consequences these will have for your build.
Finally, I want to clean up this whole mess, because it is a mess — see #308 and andlabs/ui#281.
@andlabs Thanks for your quick reply
I managed to build main.exe
with the following command without getting compiler errors
g++ main.c -Iinclude -Llib -lui -l:libui.res -luser32 -lkernel32 -lusp10 -lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc -o main.exe
However, the binary does not work. When I run it through the double-click, it flashes a cmd window and closed. When I run it with the command line, it gives the following runtime error:
error initializing ui: error initializing libui: initializing Common Controls; code 0 (0x00000000) 鎿嶄綔鎴愬姛瀹屾垚銆?
Since I am not as nearly familiar with c++ (or g++) as I am for c, I have a hard time debugging these errors. Can you help me with it?
Also, I don't quite understand what do you mean by mentioning -static -static-libgcc -static-libstdc++
, do I need to pass these flags somewhere?
Thanks
I don't understand that error message. What is 鎿嶄綔鎴愬姛瀹屾垚銆
? Neither Google nor Google Translate is giving me much insight. Furthermore, if InitCommonControlsEx()
is failing with last error 0, then something is seriously wrong...
(That weird string did expose another random bug in libui when I used it in a test run; thanks. If uiFreeText()
crashes for you, a fix is forthcoming.)
I tried to rebuild the library with the same configuration of the latest source (which is currently 465 commits ahead of the Alpha 3.5 release) and the build was failed on Windows.
C:\Users\111111\Desktop\libui-master\build>mingw32-make -f Makefile -j4 2> log.txt
[ 1%] Building C object CMakeFiles/libui.dir/common/attrlist.c.obj
[ 2%] Building C object CMakeFiles/libui.dir/common/attribute.c.obj
[ 4%] Building C object CMakeFiles/libui.dir/common/areaevents.c.obj
[ 5%] Building C object CMakeFiles/libui.dir/common/attrstr.c.obj
[ 7%] Building C object CMakeFiles/libui.dir/common/control.c.obj
[ 8%] Building C object CMakeFiles/libui.dir/common/debug.c.obj
[ 10%] Building C object CMakeFiles/libui.dir/common/matrix.c.obj
[ 11%] Building C object CMakeFiles/libui.dir/common/opentype.c.obj
[ 13%] Building C object CMakeFiles/libui.dir/common/shouldquit.c.obj
[ 14%] Building C object CMakeFiles/libui.dir/common/userbugs.c.obj
[ 16%] Building C object CMakeFiles/libui.dir/common/utf.c.obj
[ 17%] Building CXX object CMakeFiles/libui.dir/windows/alloc.cpp.obj
[ 19%] Building CXX object CMakeFiles/libui.dir/windows/areadraw.cpp.obj
[ 20%] Building CXX object CMakeFiles/libui.dir/windows/area.cpp.obj
[ 22%] Building CXX object CMakeFiles/libui.dir/windows/areaevents.cpp.obj
[ 23%] Building CXX object CMakeFiles/libui.dir/windows/areascroll.cpp.obj
[ 25%] Building CXX object CMakeFiles/libui.dir/windows/areautil.cpp.obj
[ 26%] Building CXX object CMakeFiles/libui.dir/windows/attrstr.cpp.obj
[ 27%] Building CXX object CMakeFiles/libui.dir/windows/box.cpp.obj
[ 29%] Building CXX object CMakeFiles/libui.dir/windows/button.cpp.obj
[ 30%] Building CXX object CMakeFiles/libui.dir/windows/checkbox.cpp.obj
C:\Users\111111\Desktop\libui-master\build>
I record the errors into a log file that shows some weird errors seem to be in attrstr.cpp
in windows folder.
C:\Users\111111\Desktop\libui-master\common\attrlist.c: In function 'uiprivAttrListRemoveAttribute':
C:\Users\111111\Desktop\libui-master\common\attrlist.c:505:15: warning: variable 'tailsAt' set but not used [-Wunused-but-set-variable]
struct attr *tailsAt = NULL;
^~~~~~~
C:\Users\111111\Desktop\libui-master\common\attrlist.c: In function 'uiprivAttrListRemoveAttributes':
C:\Users\111111\Desktop\libui-master\common\attrlist.c:552:15: warning: variable 'tailsAt' set but not used [-Wunused-but-set-variable]
struct attr *tailsAt = NULL;
^~~~~~~
C:\Users\111111\Desktop\libui-master\common\attribute.c: In function 'uiprivAttributeRelease':
C:\Users\111111\Desktop\libui-master\common\attribute.c:65:76: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
/* TODO implementation bug: we can't release an attribute we don't own */;
^
C:\Users\111111\Desktop\libui-master\common\attribute.c: In function 'uiFreeAttribute':
C:\Users\111111\Desktop\libui-master\common\attribute.c:74:65: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
/* TODO user bug: you can't free an attribute you don't own */;
^
C:\Users\111111\Desktop\libui-master\windows\areascroll.cpp:182:13: warning: 'void vscrollto(uiArea*, int)' defined but not used [-Wunused-function]
static void vscrollto(uiArea *a, int pos)
^~~~~~~~~
C:\Users\111111\Desktop\libui-master\windows\areascroll.cpp:137:13: warning: 'void hscrollto(uiArea*, int)' defined but not used [-Wunused-function]
static void hscrollto(uiArea *a, int pos)
^~~~~~~~~
In file included from C:\Users\111111\Desktop\libui-master\windows\winapi.hpp:36:0,
from C:\Users\111111\Desktop\libui-master\windows\uipriv_windows.hpp:2,
from C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:2:
C:\Users\111111\Desktop\libui-master\windows\attrstr.hpp:21:8: error: 'IDWriteTypography_layout_has_not_been_verified_and_its_declaration_is_most_likely_incorrect' does not name a type
extern IDWriteTypography *uiprivOpenTypeFeaturesToIDWriteTypography(const uiOpenTypeFeatures *otf);
^
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp: In member function 'virtual ULONG combinedEffectsAttr::Release()':
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:116:11: warning: deleting object of polymorphic class type 'combinedEffectsAttr' which has non-virtual destructor might cause undefined behavior [-Wdelete-non-virtual-dtor]
delete this;
^~~~
C:\Users\111111\Desktop\libui-master\windows\box.cpp: In function 'void boxRelayout(uiBox*)':
C:\Users\111111\Desktop\libui-master\windows\box.cpp:38:6: warning: unused variable 'i' [-Wunused-variable]
int i;
^
C:\Users\111111\Desktop\libui-master\windows\box.cpp:41:19: warning: unused variable 'd' [-Wunused-variable]
uiWindowsSizing *d;
^
C:\Users\111111\Desktop\libui-master\windows\box.cpp: In function 'void uiBoxMinimumSize(uiWindowsControl*, int*, int*)':
C:\Users\111111\Desktop\libui-master\windows\box.cpp:167:6: warning: unused variable 'i' [-Wunused-variable]
int i;
^
C:\Users\111111\Desktop\libui-master\windows\box.cpp:170:18: warning: unused variable 'sizing' [-Wunused-variable]
uiWindowsSizing sizing;
^~~~~~
In file included from C:\Users\111111\Desktop\libui-master\windows\winapi.hpp:36:0,
from C:\Users\111111\Desktop\libui-master\windows\uipriv_windows.hpp:2,
from C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:2:
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp: In function 'uiForEach processAttribute(const uiAttributedString*, const uiAttribute*, size_t, size_t, void*)':
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:285:2: error: 'IDWriteTypography_layout_has_not_been_verified_and_its_declaration_is_most_likely_incorrect' was not declared in this scope
IDWriteTypography *dt;
^
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:285:21: error: 'dt' was not declared in this scope
IDWriteTypography *dt;
^~
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:354:8: error: 'uiprivOpenTypeFeaturesToIDWriteTypography' was not declared in this scope
dt = uiprivOpenTypeFeaturesToIDWriteTypography(uiAttributeFeatures(attr));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:354:8: note: suggested alternative: 'uiprivOpenTypeFeaturesEqual'
dt = uiprivOpenTypeFeaturesToIDWriteTypography(uiAttributeFeatures(attr));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uiprivOpenTypeFeaturesEqual
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:336:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (hr != S_OK)
^~
C:\Users\111111\Desktop\libui-master\windows\attrstr.cpp:339:2: note: here
case uiAttributeTypeColor:
^~~~
mingw32-make[2]: *** [CMakeFiles\libui.dir\build.make:301: CMakeFiles/libui.dir/windows/attrstr.cpp.obj] Error 1
mingw32-make[2]: *** Waiting for unfinished jobs....
mingw32-make[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/libui.dir/all] Error 2
mingw32-make: *** [Makefile:83: all] Error 2
In current master msys2 build almost works:
set PATH=C:\msys64\mingw64\bin;%PATH%
md build && cd build
cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=OFF ..
mingw32-make
Result:
...
[100%] Linking CXX static library out\libui.a
Copying libui.res
Error copying file "F:/src/libui/build/CMakeFiles/libui.dir/windows/resources.rc.*" to "F:/src/libui/build/out/libui.res".
mingw32-make[2]: *** [CMakeFiles\libui.dir\build.make:1134: out/libui.a] Error 1
mingw32-make[2]: *** Deleting file 'out/libui.a'
mingw32-make[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/libui.dir/all] Error 2
mingw32-make: *** [Makefile:83: all] Error 2
After I change one line, build finished successfully:
diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt
index eab9ca9..bb5a306 100644
--- a/windows/CMakeLists.txt
+++ b/windows/CMakeLists.txt
@@ -75,7 +75,7 @@ macro(_handle_static)
add_custom_command(
TARGET libui POST_BUILD
COMMAND
- ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:libui,BINARY_DIR>/CMakeFiles/libui.dir/windows/resources.rc.* ${_LIBUI_STATIC_RES}
+ ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:libui,BINARY_DIR>/CMakeFiles/libui.dir/windows/resources.rc.obj ${_LIBUI_STATIC_RES}
COMMENT "Copying libui.res")
endmacro()
But I'm unsure if it is correct fix, What it will break?
Well, I guess that asterisk should be replaced by $<CMAKE_C_OUTPUT_EXTENSION>
What's the difference here? Does mingw32-make
or whatever shell it uses not handle the asterisk properly?
I want to get rid of these kludges entirely, but I don't have an ETA on that. In the meantime, I can accept these fixes, subject to the minimum version of $<CMAKE_C_OUTPUT_EXTENSION>
(both the variable itself and the $<>
).
I still need an explanation of why that change makes things behave differently. IIRC I had no problems with my own MSYS build a few days ago (though that was from within MSYS using -G"MSYS Makefiles"
).
I decided to just fix the problem by not having it in the first place: there is no more .res file to copy out or link in. Do things work now?
Thanks, now static build works. Dynamic still don't, but anyway on windows static is almost always preferred. :)
Just one thing I'm not entirely happy - contents of build/out
:
controlgallery.exe
cpp-multithread.exe
drawtext.exe
histogram.exe
test.exe
timer.exe
libcontrolgallery.dll.a
libcpp-multithread.dll.a
libdrawtext.dll.a
libhistogram.dll.a
libtest.dll.a
libtimer.dll.a
libui.a
Why all that *.dll.a
here?
I think that's cmake's doing; I'm not sure.
What happens on a dynamic build?
Without -DBUILD_SHARED_LIBS=OFF
cmake fails:
set "PATH=C:\msys64\mingw64\bin;%PATH%"
md build && cd build
cmake -G "MinGW Makefiles" ..
Result:
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at windows/CMakeLists.txt:89 (message):
Sorry, but libui for Windows can currently only be built as a static
library with MinGW. You will need to either build as a static library or
switch to MSVC.
-- Configuring incomplete, errors occurred!
Oh right, you're building on MinGW-w64. Yeah, DLLs aren't supported with that yet... I wonder when they will add isolation awareness support (if at all).
Hm. I tried to remove last if
in windows/CMakeLists.txt
- actually build works, but resulted programs are not "themed" - like in Windows-95.
Yes, because isolation awareness is needed for the DLL to get Common Controls 6. Otherwise, you would have to apply the respective manifest to the whole application. Side-by-Side Assemblies is weird.
Any updates?
I have started properly documenting libui, and there will now be a page for how to properly use libui as a static library. The page will not be relevant to the current release, but it will be to the next.
After reading this problem, I finally succeeded in using a static library, so I can record it. Is it useful to you, I use mingw32 under msys2
I download static lib from here: libs
// 2 september 2015
#include <stdio.h>
#include <string.h>
#include "ui.h"
static int onClosing(uiWindow *w, void *data)
{
uiQuit();
return 1;
}
static int onShouldQuit(void *data)
{
uiWindow *mainwin = uiWindow(data);
uiControlDestroy(uiControl(mainwin));
return 1;
}
static uiControl *makeBasicControlsPage(void)
{
uiBox *vbox;
uiBox *hbox;
uiGroup *group;
uiForm *entryForm;
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
hbox = uiNewHorizontalBox();
uiBoxSetPadded(hbox, 1);
uiBoxAppend(vbox, uiControl(hbox), 0);
uiBoxAppend(hbox,
uiControl(uiNewButton("Button")),
0);
uiBoxAppend(hbox,
uiControl(uiNewCheckbox("Checkbox")),
0);
uiBoxAppend(vbox,
uiControl(uiNewLabel("This is a label. Right now, labels can only span one line.")),
0);
uiBoxAppend(vbox,
uiControl(uiNewHorizontalSeparator()),
0);
group = uiNewGroup("Entries");
uiGroupSetMargined(group, 1);
uiBoxAppend(vbox, uiControl(group), 1);
entryForm = uiNewForm();
uiFormSetPadded(entryForm, 1);
uiGroupSetChild(group, uiControl(entryForm));
uiFormAppend(entryForm,
"Entry",
uiControl(uiNewEntry()),
0);
uiFormAppend(entryForm,
"Password Entry",
uiControl(uiNewPasswordEntry()),
0);
uiFormAppend(entryForm,
"Search Entry",
uiControl(uiNewSearchEntry()),
0);
uiFormAppend(entryForm,
"Multiline Entry",
uiControl(uiNewMultilineEntry()),
1);
uiFormAppend(entryForm,
"Multiline Entry No Wrap",
uiControl(uiNewNonWrappingMultilineEntry()),
1);
return uiControl(vbox);
}
// TODO make these not global
static uiSpinbox *spinbox;
static uiSlider *slider;
static uiProgressBar *pbar;
static void onSpinboxChanged(uiSpinbox *s, void *data)
{
uiSliderSetValue(slider, uiSpinboxValue(s));
uiProgressBarSetValue(pbar, uiSpinboxValue(s));
}
static void onSliderChanged(uiSlider *s, void *data)
{
uiSpinboxSetValue(spinbox, uiSliderValue(s));
uiProgressBarSetValue(pbar, uiSliderValue(s));
}
static uiControl *makeNumbersPage()
{
uiBox *hbox;
uiGroup *group;
uiBox *vbox;
uiProgressBar *ip;
uiCombobox *cbox;
uiEditableCombobox *ecbox;
uiRadioButtons *rb;
hbox = uiNewHorizontalBox();
uiBoxSetPadded(hbox, 1);
group = uiNewGroup("Numbers");
uiGroupSetMargined(group, 1);
uiBoxAppend(hbox, uiControl(group), 1);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiGroupSetChild(group, uiControl(vbox));
spinbox = uiNewSpinbox(0, 100);
slider = uiNewSlider(0, 100);
pbar = uiNewProgressBar();
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
uiSliderOnChanged(slider, onSliderChanged, NULL);
uiBoxAppend(vbox, uiControl(spinbox), 0);
uiBoxAppend(vbox, uiControl(slider), 0);
uiBoxAppend(vbox, uiControl(pbar), 0);
ip = uiNewProgressBar();
uiProgressBarSetValue(ip, -1);
uiBoxAppend(vbox, uiControl(ip), 0);
group = uiNewGroup("Lists");
uiGroupSetMargined(group, 1);
uiBoxAppend(hbox, uiControl(group), 1);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiGroupSetChild(group, uiControl(vbox));
cbox = uiNewCombobox();
uiComboboxAppend(cbox, "Combobox Item 1");
uiComboboxAppend(cbox, "Combobox Item 2");
uiComboboxAppend(cbox, "Combobox Item 3");
uiBoxAppend(vbox, uiControl(cbox), 0);
ecbox = uiNewEditableCombobox();
uiEditableComboboxAppend(ecbox, "Editable Item 1");
uiEditableComboboxAppend(ecbox, "Editable Item 2");
uiEditableComboboxAppend(ecbox, "Editable Item 3");
uiBoxAppend(vbox, uiControl(ecbox), 0);
rb = uiNewRadioButtons();
uiRadioButtonsAppend(rb, "Radio Button 1");
uiRadioButtonsAppend(rb, "Radio Button 2");
uiRadioButtonsAppend(rb, "Radio Button 3");
uiBoxAppend(vbox, uiControl(rb), 0);
return uiControl(hbox);
}
// TODO make this not global
static uiWindow *mainwin;
static void onOpenFileClicked(uiButton *b, void *data)
{
uiEntry *entry = uiEntry(data);
char *filename;
filename = uiOpenFile(mainwin);
if (filename == NULL) {
uiEntrySetText(entry, "(cancelled)");
return;
}
uiEntrySetText(entry, filename);
uiFreeText(filename);
}
static void onSaveFileClicked(uiButton *b, void *data)
{
uiEntry *entry = uiEntry(data);
char *filename;
filename = uiSaveFile(mainwin);
if (filename == NULL) {
uiEntrySetText(entry, "(cancelled)");
return;
}
uiEntrySetText(entry, filename);
uiFreeText(filename);
}
static void onMsgBoxClicked(uiButton *b, void *data)
{
uiMsgBox(mainwin,
"This is a normal message box.",
"More detailed information can be shown here.");
}
static void onMsgBoxErrorClicked(uiButton *b, void *data)
{
uiMsgBoxError(mainwin,
"This message box describes an error.",
"More detailed information can be shown here.");
}
static uiControl *makeDataChoosersPage(void)
{
uiBox *hbox;
uiBox *vbox;
uiGrid *grid;
uiButton *button;
uiEntry *entry;
uiGrid *msggrid;
hbox = uiNewHorizontalBox();
uiBoxSetPadded(hbox, 1);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiBoxAppend(hbox, uiControl(vbox), 0);
uiBoxAppend(vbox,
uiControl(uiNewDatePicker()),
0);
uiBoxAppend(vbox,
uiControl(uiNewTimePicker()),
0);
uiBoxAppend(vbox,
uiControl(uiNewDateTimePicker()),
0);
uiBoxAppend(vbox,
uiControl(uiNewFontButton()),
0);
uiBoxAppend(vbox,
uiControl(uiNewColorButton()),
0);
uiBoxAppend(hbox,
uiControl(uiNewVerticalSeparator()),
0);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiBoxAppend(hbox, uiControl(vbox), 1);
grid = uiNewGrid();
uiGridSetPadded(grid, 1);
uiBoxAppend(vbox, uiControl(grid), 0);
button = uiNewButton("Open File");
entry = uiNewEntry();
uiEntrySetReadOnly(entry, 1);
uiButtonOnClicked(button, onOpenFileClicked, entry);
uiGridAppend(grid, uiControl(button),
0, 0, 1, 1,
0, uiAlignFill, 0, uiAlignFill);
uiGridAppend(grid, uiControl(entry),
1, 0, 1, 1,
1, uiAlignFill, 0, uiAlignFill);
button = uiNewButton("Save File");
entry = uiNewEntry();
uiEntrySetReadOnly(entry, 1);
uiButtonOnClicked(button, onSaveFileClicked, entry);
uiGridAppend(grid, uiControl(button),
0, 1, 1, 1,
0, uiAlignFill, 0, uiAlignFill);
uiGridAppend(grid, uiControl(entry),
1, 1, 1, 1,
1, uiAlignFill, 0, uiAlignFill);
msggrid = uiNewGrid();
uiGridSetPadded(msggrid, 1);
uiGridAppend(grid, uiControl(msggrid),
0, 2, 2, 1,
0, uiAlignCenter, 0, uiAlignStart);
button = uiNewButton("Message Box");
uiButtonOnClicked(button, onMsgBoxClicked, NULL);
uiGridAppend(msggrid, uiControl(button),
0, 0, 1, 1,
0, uiAlignFill, 0, uiAlignFill);
button = uiNewButton("Error Box");
uiButtonOnClicked(button, onMsgBoxErrorClicked, NULL);
uiGridAppend(msggrid, uiControl(button),
1, 0, 1, 1,
0, uiAlignFill, 0, uiAlignFill);
return uiControl(hbox);
}
int main(void)
{
uiInitOptions options;
const char *err;
uiTab *tab;
memset(&options, 0, sizeof (uiInitOptions));
err = uiInit(&options);
if (err != NULL) {
fprintf(stderr, "error initializing libui: %s", err);
uiFreeInitError(err);
return 1;
}
mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1);
uiWindowOnClosing(mainwin, onClosing, NULL);
uiOnShouldQuit(onShouldQuit, mainwin);
tab = uiNewTab();
uiWindowSetChild(mainwin, uiControl(tab));
uiWindowSetMargined(mainwin, 1);
uiTabAppend(tab, "Basic Controls", makeBasicControlsPage());
uiTabSetMargined(tab, 0, 1);
uiTabAppend(tab, "Numbers and Lists", makeNumbersPage());
uiTabSetMargined(tab, 1, 1);
uiTabAppend(tab, "Data Choosers", makeDataChoosersPage());
uiTabSetMargined(tab, 2, 1);
uiControlShow(uiControl(mainwin));
uiMain();
return 0;
}
#if 0
static void openClicked(uiMenuItem *item, uiWindow *w, void *data)
{
char *filename;
filename = uiOpenFile(mainwin);
if (filename == NULL) {
uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!");
return;
}
uiMsgBox(mainwin, "File selected", filename);
uiFreeText(filename);
}
static void saveClicked(uiMenuItem *item, uiWindow *w, void *data)
{
char *filename;
filename = uiSaveFile(mainwin);
if (filename == NULL) {
uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!");
return;
}
uiMsgBox(mainwin, "File selected (don't worry, it's still there)", filename);
uiFreeText(filename);
}
static uiSpinbox *spinbox;
static uiSlider *slider;
static uiProgressBar *progressbar;
static void update(int value)
{
uiSpinboxSetValue(spinbox, value);
uiSliderSetValue(slider, value);
uiProgressBarSetValue(progressbar, value);
}
static void onSpinboxChanged(uiSpinbox *s, void *data)
{
update(uiSpinboxValue(spinbox));
}
static void onSliderChanged(uiSlider *s, void *data)
{
update(uiSliderValue(slider));
}
int main(int argc, char* [] argv)
{
uiInitOptions o;
const char *err;
uiMenu *menu;
uiMenuItem *item;
uiBox *box;
uiBox *hbox;
uiGroup *group;
uiBox *inner;
uiBox *inner2;
uiEntry *entry;
uiCombobox *cbox;
uiEditableCombobox *ecbox;
uiRadioButtons *rb;
uiTab *tab;
memset(&o, 0, sizeof (uiInitOptions));
err = uiInit(&o);
if (err != NULL) {
fprintf(stderr, "error initializing ui: %s\n", err);
uiFreeInitError(err);
return 1;
}
menu = uiNewMenu("File");
item = uiMenuAppendItem(menu, "Open");
uiMenuItemOnClicked(item, openClicked, NULL);
item = uiMenuAppendItem(menu, "Save");
uiMenuItemOnClicked(item, saveClicked, NULL);
item = uiMenuAppendQuitItem(menu);
uiOnShouldQuit(shouldQuit, NULL);
menu = uiNewMenu("Edit");
item = uiMenuAppendCheckItem(menu, "Checkable Item");
uiMenuAppendSeparator(menu);
item = uiMenuAppendItem(menu, "Disabled Item");
uiMenuItemDisable(item);
item = uiMenuAppendPreferencesItem(menu);
menu = uiNewMenu("Help");
item = uiMenuAppendItem(menu, "Help");
item = uiMenuAppendAboutItem(menu);
mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1);
uiWindowSetMargined(mainwin, 1);
uiWindowOnClosing(mainwin, onClosing, NULL);
box = uiNewVerticalBox();
uiBoxSetPadded(box, 1);
uiWindowSetChild(mainwin, uiControl(box));
hbox = uiNewHorizontalBox();
uiBoxSetPadded(hbox, 1);
uiBoxAppend(box, uiControl(hbox), 1);
group = uiNewGroup("Basic Controls");
uiGroupSetMargined(group, 1);
uiBoxAppend(hbox, uiControl(group), 0);
inner = uiNewVerticalBox();
uiBoxSetPadded(inner, 1);
uiGroupSetChild(group, uiControl(inner));
uiBoxAppend(inner,
uiControl(uiNewButton("Button")),
0);
uiBoxAppend(inner,
uiControl(uiNewCheckbox("Checkbox")),
0);
entry = uiNewEntry();
uiEntrySetText(entry, "Entry");
uiBoxAppend(inner,
uiControl(entry),
0);
uiBoxAppend(inner,
uiControl(uiNewLabel("Label")),
0);
uiBoxAppend(inner,
uiControl(uiNewHorizontalSeparator()),
0);
uiBoxAppend(inner,
uiControl(uiNewDatePicker()),
0);
uiBoxAppend(inner,
uiControl(uiNewTimePicker()),
0);
uiBoxAppend(inner,
uiControl(uiNewDateTimePicker()),
0);
uiBoxAppend(inner,
uiControl(uiNewFontButton()),
0);
uiBoxAppend(inner,
uiControl(uiNewColorButton()),
0);
inner2 = uiNewVerticalBox();
uiBoxSetPadded(inner2, 1);
uiBoxAppend(hbox, uiControl(inner2), 1);
group = uiNewGroup("Numbers");
uiGroupSetMargined(group, 1);
uiBoxAppend(inner2, uiControl(group), 0);
inner = uiNewVerticalBox();
uiBoxSetPadded(inner, 1);
uiGroupSetChild(group, uiControl(inner));
spinbox = uiNewSpinbox(0, 100);
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
uiBoxAppend(inner, uiControl(spinbox), 0);
slider = uiNewSlider(0, 100);
uiSliderOnChanged(slider, onSliderChanged, NULL);
uiBoxAppend(inner, uiControl(slider), 0);
progressbar = uiNewProgressBar();
uiBoxAppend(inner, uiControl(progressbar), 0);
group = uiNewGroup("Lists");
uiGroupSetMargined(group, 1);
uiBoxAppend(inner2, uiControl(group), 0);
inner = uiNewVerticalBox();
uiBoxSetPadded(inner, 1);
uiGroupSetChild(group, uiControl(inner));
cbox = uiNewCombobox();
uiComboboxAppend(cbox, "Combobox Item 1");
uiComboboxAppend(cbox, "Combobox Item 2");
uiComboboxAppend(cbox, "Combobox Item 3");
uiBoxAppend(inner, uiControl(cbox), 0);
ecbox = uiNewEditableCombobox();
uiEditableComboboxAppend(ecbox, "Editable Item 1");
uiEditableComboboxAppend(ecbox, "Editable Item 2");
uiEditableComboboxAppend(ecbox, "Editable Item 3");
uiBoxAppend(inner, uiControl(ecbox), 0);
rb = uiNewRadioButtons();
uiRadioButtonsAppend(rb, "Radio Button 1");
uiRadioButtonsAppend(rb, "Radio Button 2");
uiRadioButtonsAppend(rb, "Radio Button 3");
uiBoxAppend(inner, uiControl(rb), 1);
tab = uiNewTab();
uiTabAppend(tab, "Page 1", uiControl(uiNewHorizontalBox()));
uiTabAppend(tab, "Page 2", uiControl(uiNewHorizontalBox()));
uiTabAppend(tab, "Page 3", uiControl(uiNewHorizontalBox()));
uiBoxAppend(inner2, uiControl(tab), 1);
uiControlShow(uiControl(mainwin));
uiMain();
uiUninit();
return 0;
}
#endif
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>Your application description here.</description>
<!-- we DO need comctl6 in the static case -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application>
</compatibility>
</assembly>
// 30 may 2015
// this is a UTF-8 file
#pragma code_page(65001)
// this is the Common Controls 6 manifest
// TODO set up the string values here
// 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples
1 24 "lui.static.manifest"
CC=g++
RM=rm -f
TGT=lui.exe
OBJS=testlui.o resource.o
LINKS=-static -static-libgcc -static-libstdc++ -lui -luser32 -lkernel32 -lusp10 \
-lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc \
# -mwindows
all: $(OBJS)
$(CC) $(OBJS) $(LINKS) -o $(TGT)
testlui.o: testlui.c
$(CC) -c testlui.c
resource.o: resource.rc
windres -i resource.rc -o resource.o
.PHONEY: clean
clean:
$(RM) *.o
I know this question may be dumb, but I just can't figure out how to do it.
I successfully compiled the program with
CMake 3.11
onWindows 7 x86
withmingw32 gcc 7.2.0
and it gives two files: onelibui.a
and anotherlibui.res
. I want to test this library so I build the examples withmingw32-make -f Makefile examples
using theMakefile
generated byCMake
, and it works as well.But I wonder how I can use this library in my own project without
CMake
since I am not an expert on CMake and I don't want to mess up with it. So I copy themain.c
inside theexamples\histogram
as well asui.h
and the two library files listed above to another location and run the following command in the folder containingmain.c
I am expecting this to work since
main.c
only includesui.h
besides standard library andui.h
does not include other external headers as well. but it does work and throws me a bunch of undefined references. The stderr is attached:Before I compile the library myself, I use the prebuild static library for mingw in the
Alpha 3.5
release andtdm-gcc 5.1.0
to buildmain.c
. The compiler throw me something similar:And now I am frustrated of what I should do. I really love this project since this seemed to be the only lightweight crossplatform GUI library for C on the Internet. So it is highly appreciated if any one can help.