C++ kompilacja programu

Witajcie

Otóż mam problem ze skompilowaniem programu tak żeby uruchomić go na drugim kompie. Gdy komplikuje go to mogę go uruchomić tylko u siebie, a na drugim sprzęcie pisze “Ponowne zainstalowanie aplikacji może naprawić błąd”…

Napisałem sobie taki oto program wiem, wiem podstawy. Ale uczę się dopiero.

#pragma once


#include 

namespace My3 {




	using namespace System;

	using namespace System::ComponentModel;

	using namespace System::Collections;

	using namespace System::Windows::Forms;

	using namespace System::Data;

	using namespace System::Drawing;


	/// 

	/// Summary for Form1

	///

	/// WARNING: If you change the name of this class, you will need to change the

	/// 'Resource File Name' property for the managed resource compiler tool

	/// associated with all .resx files this class depends on. Otherwise,

	/// the designers will not be able to interact properly with localized

	/// resources associated with this form.

	/// 

	public ref class Form1 : public System::Windows::Forms::Form

	{

	public:

		Form1(void)

		{

			InitializeComponent();

			//

			//TODO: Add the constructor code here

			//

		}


	protected:

		/// 

		/// Clean up any resources being used.

		/// 

		~Form1()

		{

			if (components)

			{

				delete components;

			}

		}

	private: System::Windows::Forms::Button^ button1;

	protected: 

	private: System::Windows::Forms::TextBox^ textBox1;

	private: System::Windows::Forms::TextBox^ textBox2;

	private: System::Windows::Forms::Label^ label1;

	private: System::Windows::Forms::Label^ label2;

	private: System::Windows::Forms::Label^ label3;

	private: System::Windows::Forms::Label^ label4;


	private:

		/// 

		/// Required designer variable.

		/// 

		System::ComponentModel::Container ^components;


#pragma region Windows Form Designer generated code

		/// 

		/// Required method for Designer support - do not modify

		/// the contents of this method with the code editor.

		/// 

		void InitializeComponent(void)

		{

			this->button1 = (gcnew System::Windows::Forms::Button());

			this->textBox1 = (gcnew System::Windows::Forms::TextBox());

			this->textBox2 = (gcnew System::Windows::Forms::TextBox());

			this->label1 = (gcnew System::Windows::Forms::Label());

			this->label2 = (gcnew System::Windows::Forms::Label());

			this->label3 = (gcnew System::Windows::Forms::Label());

			this->label4 = (gcnew System::Windows::Forms::Label());

			this->SuspendLayout();

			// 

			// button1

			// 

			this->button1->Location = System::Drawing::Point(37, 150);

			this->button1->Name = L"button1";

			this->button1->Size = System::Drawing::Size(75, 23);

			this->button1->TabIndex = 0;

			this->button1->Text = L"licz!";

			this->button1->UseVisualStyleBackColor = true;

			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);

			// 

			// textBox1

			// 

			this->textBox1->Location = System::Drawing::Point(25, 74);

			this->textBox1->Name = L"textBox1";

			this->textBox1->Size = System::Drawing::Size(100, 20);

			this->textBox1->TabIndex = 1;

			// 

			// textBox2

			// 

			this->textBox2->Location = System::Drawing::Point(25, 124);

			this->textBox2->Name = L"textBox2";

			this->textBox2->Size = System::Drawing::Size(100, 20);

			this->textBox2->TabIndex = 2;

			// 

			// label1

			// 

			this->label1->AutoSize = true;

			this->label1->Location = System::Drawing::Point(25, 55);

			this->label1->Name = L"label1";

			this->label1->Size = System::Drawing::Size(96, 13);

			this->label1->TabIndex = 3;

			this->label1->Text = L"Krawędź podstawy";

			// 

			// label2

			// 

			this->label2->AutoSize = true;

			this->label2->Location = System::Drawing::Point(25, 105);

			this->label2->Name = L"label2";

			this->label2->Size = System::Drawing::Size(110, 13);

			this->label2->TabIndex = 4;

			this->label2->Text = L"Wysokość ostrosłupa";

			// 

			// label3

			// 

			this->label3->AutoSize = true;

			this->label3->Location = System::Drawing::Point(12, 9);

			this->label3->Name = L"label3";

			this->label3->Size = System::Drawing::Size(129, 13);

			this->label3->TabIndex = 5;

			this->label3->Text = L"Pole i objętość ostrosłupa";

			// 

			// label4

			// 

			this->label4->AutoSize = true;

			this->label4->Location = System::Drawing::Point(1, 22);

			this->label4->Name = L"label4";

			this->label4->Size = System::Drawing::Size(150, 13);

			this->label4->TabIndex = 6;

			this->label4->Text = L"czworokątnego prawidłowego";

			// 

			// Form1

			// 

			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);

			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

			this->ClientSize = System::Drawing::Size(151, 186);

			this->Controls->Add(this->label4);

			this->Controls->Add(this->label3);

			this->Controls->Add(this->label2);

			this->Controls->Add(this->label1);

			this->Controls->Add(this->textBox2);

			this->Controls->Add(this->textBox1);

			this->Controls->Add(this->button1);

			this->Name = L"Form1";

			this->Text = L"Program1";

			this->ResumeLayout(false);

			this->PerformLayout();


		}

#pragma endregion

	private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) 

			 {

				 int kraw;

				 int wys;

                 double pole;

				 double wystr;

				 double wystr2;

				 double potega;

				 double obj;




		         kraw = Convert::ToInt16 (textBox1->Text);

				 wys = Convert::ToInt16 (textBox2->Text);



                 wystr = sqrt((1/2)*(double)kraw * (1/2)*(double)kraw + (double)wys * (double)wys);

                 (double)wystr2 = sqrt(wystr);


				 pole = (double)kraw * (double)kraw + (double)wystr2 * (double)kraw * 2;

                 obj = ((double)kraw * (double)kraw * (double)wys)/3;


				 MessageBox::Show ("Pole: " + Convert::ToString(pole)+ " j^2. \n" + "Objętość: " + Convert::ToString(obj)+ " j^3. \n", "Pole i objętość: ");


			 }

};

}

A więc jak go skompilować żeby działało na tym drugim kompie?

Mój kompilator to Visual C++ Express Edition 2008. Mam nadzieje że za bardzo nie zagmatwałem :stuck_out_tongue:

Z góry dzięki za odpowiedź :smiley:

Pozdrawiam

Tiger133

I właśnie kompilacja w VC++ jest błędem, na komputerze, na którym będziesz chciał odpalic program będą wymagane biblioteki VC++, czy tam jakieś inne. Moim zdaniem lepiej skorzystać z GNU GCC Compilator. Wykorzystywany on jest w IDE Code::Bzlocks jako domyślny.

Dzięki za odpowiedź :smiley:

Ale mam następny problem :oops:

jak to zainstalować ? Ściągnąłem wersie 4.3.3 …

Aha i jeszcze jedno nie ma naprawdę jakiegoś innego sposobu ? :frowning:

Ja bym się najpierw upewnił :wink: Nic nie trzeba instalować, wystarczy prawidłowo skompilować program(C+±>Code Generation = Multithreaded a nie Multithreaded DLL i dodać “libcmt.lib” i “libpcmt.lib” do ignorowanych) ewentualnie dołączać Redisty do aplikacji.

Dobra udało się nie wiem czy dobrze ale jest tak mam poustawiane:

Alt+F7->C/C+±>Code Generator->Runtime library->Multithreaded (/MT)

A to drugie znalazłem w (nie wiem czy to to):

Alt+F7->linker->Input->Ignore Specyfic Library-> (i tam to wpisałem)libcmt.lib;libpcmt.lib

Jednak przy komplikacji występuje błąd:

1>------ Build started: Project: 3, Configuration: Release Win32 ------

1>Compiling...

1>cl : Command line error D8016 : '/MT' and '/clr:pure' command-line options are incompatible

1>Build log was saved at "file://c:\Documents and Settings\uzytkownik\Moje dokumenty\Visual Studio 2008\Projects\3\3\Release\BuildLog.htm"

1>3 - 1 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Co z tym zrobić żeby zadziałało?

Ręce odpadają :expressionless:

Świetny pomysł, szkoda tylko, że GCC nie zawiera kompilatora do języka, z którego korzysta autor.

Ale to nie jest przecież C++, więc zmiana opcji dla C++ nic nie da :slight_smile:

Skoro napisałeś program w .NET, to na komputerze, na którym chcesz go uruchomić, musisz zainstalować .NET Framework. Innego wyjścia nie ma.

Kod jest w języku zarządzanym (C++/CLI), jest on “pośrodku” pomiędzy C++, a C#. Osobiście zalecałbym jednak przejście na jeden z tych dwóch. Korzystanie z użytego języka jest zasadne według mnie tylko i wyłącznie jak chcemy szybko zrobić aplikacje okienkowe, korzystające z wydajnego kodu C++. Składnia przez to jest tutaj troszkę naciągana - ze względu na zachowanie zgodności zarówno z C++ jak i .net. Dlatego lepiej skorzystać z C# gdzie korzystanie z wielu rzeczy będzie bardziej wygodne i kod będzie bardziej jednorodny. Wtedy też potrzebny jest zainstalowany .net na każdym komputerze korzystającym z naszego programu.

W przeciwnym wypadku zostaje C++ i pełna kompilacja programu do kodu maszynowego i brak potrzeby dodatkowych bibliotek, ale wtedy już trzeba samemu zadbać o interfejs graficzny.

Dobra thx za pomoc :smiley: